interpret primaryjoin where the actual FK/PK column is inside a binary expression or similar
Issue #2373
resolved
Currently SQLAlchemy doesn't allow to map relationships which have primaryjoin condition like this:
a.c.b_id + 2 == b.c.id
It just can't figure out the direction of relationships even if I supply a.c.b_id + 2 as foreign_keys element.
dupe of
Comments (6)
-
reporter -
reporter - attached sqla_ticket_2373.py
Test case
-
reporter Attached second version of test case there foreign_keys contains column and not expression.
-
repo owner - changed title to interpret primaryjoin where the actual FK/PK column is inside a binary expression or similar
- marked as minor
- changed status to duplicate
- marked as bug
this is really a dupe of
#610.You can do it like this:
mapper(A, a, { "b": relationship( B, primaryjoin=a.c.b_id + 2 == b.c.id, _local_remote_pairs = [b.c.id)]((a.c.b_id,), foreign_keys=a.c.b_id, viewonly=True) })
-
reporter Thanks, somehow I didn't spot _local_remote_pairs in RelationshipProperty constructors arguments.
-
repo owner its not entirely public. I give it to people when they ask.
- Log in to comment
Please see attached test case for more info regarding issue. I think this is good enhancement to SQLAlchemy.