Repository navigation
Replies: 1 comment
|
from_ = fields.ForeignKeyField(
"models.Account", related_name="sent_events", null=True
)
to_ = fields.ForeignKeyField(
"models.Account", related_name="received_events", null=True
)Then query either direction: sent = await account.sent_events.all()
received = await account.received_events.all()If you want one list containing both roles, query from tortoise.expressions import Q
events = await Event.filter(Q(from_=account) | Q(to_=account))Creating the event stores the foreign key IDs on the event row; you do not need a separate update to the account row to populate its reverse relations. I tested this with Tortoise ORM 1.1.8 and SQLite, including an event where the sender and recipient are the same account: the combined query returned that event once. If you do not need reverse attributes at all, |
0 replies
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Uh oh!
There was an error while loading. Please reload this page.
Hello, I need some help on the following:
I have an Event Model and an Account Model. When I want to create a new Event, I would like to store at the same time in the Account Model the reference to the event.
from_is the Account who initiated the event andto_is the Account who received the event. However, this only works when I set therelated_nameto different names. Is there a way to get around this?All reactions