BeanieODM / beanie

Asynchronous Python ODM for MongoDB

Home Page:http://beanie-odm.dev/

Geek Repo:Geek Repo

Github PK Tool:Github PK Tool

[BUG] Multilevel related document lookups don't work

thorin-schiffer opened this issue · comments

Describe the bug
If document referencing goes further than one level, find won't resolve it properly

To Reproduce

class Organization(Document):
    slug: str

class Domain(Document):
    organization: Link[Organization]
    integration: str

class Attribute(Document):
    domain: Link[Domain]

class AttributeMapping(Document):
    source: Link[Attribute]
    target: Link[Attribute]

# won't work
await AttributeMapping.find(
            AttributeMapping.source.domain.integration == domain.integration,
            AttributeMapping.source.domain.organization.slug == organization.slug,
            fetch_links=True,
        ).count()

# won't work
await AttributeMapping.find(
            AttributeMapping.source.domain.id == domain.id,
            fetch_links=True, # regardless
        ).count()

Expected behavior
Linked documents are found

Hi! I'll check what is going on there and will let you know here if this is possible to fix or not. Thank you