How do I specify a null relation in SQLAlchemy?
Posted
by Jesse
on Stack Overflow
See other posts from Stack Overflow
or by Jesse
Published on 2010-05-19T08:06:21Z
Indexed on
2010/05/19
8:10 UTC
Read the original article
Hit count: 218
Not sure what the correct title for this question should be. I have the following schema:
- Matters have a one-many relationship to WorkItems.
- WorkItems have a one-one (or one-zero) relationship to LineItems.
I am trying to create the following relation between Matters and WorkItems
Matter.unbilled_work_items = orm.relation(WorkItem,
primaryjoin = (Matter.id == WorkItem.matter_id) and (WorkItem.line_item_id == None),
foreign_keys = [WorkItem.matter_id, WorkItem.line_item_id],
viewonly=True
)
This throws:
AttributeError: '_Null' object has no attribute 'table'
That seems to be saying that the second clause in the primaryjoin returns an object of type _Null, but it seems to be expecting something with a "table" attribute.
This seems like it should be pretty straightforward to me, am I missing something obvious?
© Stack Overflow or respective owner