Hi all,
Recently I found an issue on using the back reference. Here a simple
scenario.
Table user (with primary key userId) and table event_registration (with two
foreign keys, userid referencing the user table and eventId referencing the
event table, as primary key). And we define the relationship for this two
as fk_user on event_registration and br_event_registrations on user table.
user_table = Table("user", metadata,
Column('userId', BigInteger, Sequence('user_userId_seq'), primary_key=
True),
...
)
class User(object):
pass
mapper(User, user_table, properties={})
event_registration_table = Table("event_registration", metadata,
Column('userId', BigInteger, ForeignKey('user.userId'), primary_key=True
),
Column('eventId', BigInteger, ForeignKey('event.eventId'), primary_key=
True),
...
)
class EventRegistration(object):
pass
mapper(EventRegistration, event_registration_table, properties={
'fk_user': relationship(User, backref='br_event_registrations'),
...
})
A common search query about getting the users who have registered a certain
or a series of events. For example:
for db_user in session.query(User).join(User.br_event_registrations).filter(
EventRegistrations.eventId < 10).all():
db_event_registration_list = db_user.br_event_registrations
In the db_event_registration_list, I expect to get all the registrations
for a certain user and with eventId < 10. However what I actually get are
all the registrations related to this user.
I have tried using the joinedload and joinedload_all, but it do not solve
the problem.
I'm wondering if there are some flaws on this database schema or on the
fetching process itself.
Thanks in advance!
--
You received this message because you are subscribed to the Google Groups
"sqlalchemy" group.
To unsubscribe from this group and stop receiving emails from it, send an email
to [email protected].
To post to this group, send email to [email protected].
Visit this group at http://groups.google.com/group/sqlalchemy.
For more options, visit https://groups.google.com/d/optout.