You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
When creating backlinks, the documentation (to my knowledge) doesn’t show a way to retrieve them immediately.
This question was asked in #583 but never replied, so I don’t want to bump an old discussion.
Considering the definitions below:
class IdCard(Document):
ref: Indexed(str, unique=True)
# Only one owner per id card
owner: BackLink["Person"] | None = Field(original_field="id_card")
class Person(Document):
name: str
parents: List[Link["Person"]] | None = None
kids: List[BackLink["Person"]] | None = Field(original_field="parents")
morticia = Person(name="Morticia")
gomez = Person(name="Gomez")
await morticia.insert()
await gomez.insert()
wednesday = Person(name="Wednesday", parents=[gomez, morticia])
await wednesday.insert()
The following does NOT work:
# If uncommented, AttributeError: 'BackLink' object has no attribute 'id'
# await morticia.fetch_all_links()
# AttributeError: 'BackLink' object has no attribute 'name'
print(morticia.kids[0].name)
This works:
result = await Person.find(Person.name == 'Morticia', fetch_links=True).first_or_none()
print(result.kids[0].name)
Is there a way to populate the backlink, similar to fetch_all_links with Link objects?
reacted with thumbs up emoji reacted with thumbs down emoji reacted with laugh emoji reacted with hooray emoji reacted with confused emoji reacted with heart emoji reacted with rocket emoji reacted with eyes emoji
-
When creating backlinks, the documentation (to my knowledge) doesn’t show a way to retrieve them immediately.
This question was asked in #583 but never replied, so I don’t want to bump an old discussion.
Considering the definitions below:
The following does NOT work:
This works:
Is there a way to populate the backlink, similar to fetch_all_links with Link objects?
Thank you!
Beta Was this translation helpful? Give feedback.
All reactions