Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Поддержка множественных MAToOneRelationDescription к одной таблице в MagritteSQLAlchemy #121

Open
rybalchenkoserg opened this issue Apr 16, 2024 · 0 comments

Comments

@rybalchenkoserg
Copy link
Collaborator

Если в контейнере используются несколько MAToOneRelationDescription для связи с одним и тем же объектом, то в таблице БД создается только первая связь. Пример:

class Host(MAModel):
    address = ""
    protocol = ""  
 
host_desc = MAContainer()   
host_desc.name = 'Host'
host_desc.setChildren(
    [
        MAStringDescription(
            name='address', label='Ip Address', required=True, accessor=MAAttrAccessor('address'),
            sa_isPrimaryKey=True, 
        ),
        MAStringDescription(
            name='protocol', label='Protocol', required=True, accessor=MAAttrAccessor('protocol'),
        ),
    ]
)

class Interface(MAModel):
    interface=""
    ip4=""
    gateway=""

interface_desc = MAContainer()   
interface_desc.name = 'Interface'
interface_desc.setChildren(
    [
        MAStringDescription(
            name='interface', label='Interface', required=True, accessor=MAAttrAccessor('interface')
            , sa_isPrimaryKey=True
        ),
        MAToOneRelationDescription(
            name='ip4_addr', label='IP4 Address', required=True,
            accessor=MAAttrAccessor('ip4_addr'), classes=[Host],
            reference=host_desc
        ),
        MAToOneRelationDescription(
            name='gateway', label='Gateway', accessor=MAAttrAccessor('gateway'), classes=[Host],
            reference=host_desc
        )
    ]
)

В этом случае, в таблице Interface будет содано только поле только для ip4_addr, для gateway поле не создается.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

No branches or pull requests

1 participant