- changed title to query() should interpret a many-to-one relation() as an entity?
- changed milestone to 0.5.xx
- marked as enhancement
query() should interpret a many-to-one relation() as an entity?
The following query:
list(session.query(Employee, Employee.company))
unexpectedly returns 5-element tuples
[e1, 1, u'e1', u'employee', 1),
(Employee e2, 2, u'e2', u'employee', 1),
(Employee e3, 3, u'e3', u'employee', 2)]((Employee)
IMHO no one expects such a result.
Full test case attached.
Comments (11)
-
repo owner -
Account Deleted I agree, that raising an error is a good solution.
-
repo owner lately I've been swinging the other way on this. if you query(Parent.child), it really is obvious what you're looking for. just wondering about implementation.
-
repo owner - marked as critical
-
Account Deleted Here's a patch that adds some tests and an implementation. It touches a fair amount of code, but a lot of that is just to add a simple way for queries to join themselves.
Also, the only tests this has are the basic query(Parent.child) case and the add_entity(Parent.child) case. Are there others?
Final thought: should this work for one-to-many relations as well? e.g. query(Child.parents)
-Scott Torborg
-
Account Deleted Can someone add storborg@mit.edu to the cc list for this ticket please?
-
Account Deleted - changed watchers to accek@mimuw.edu.pl, storborg@mit.edu
(original author: ged)
-
Account Deleted Is this related to my stackoverflow question?
sounds like it, and I sure didn't expect it.
-
repo owner - marked as major
-
repo owner - changed status to duplicate
consolidating under #2846
-
repo owner - changed milestone to 1.x.xx
- Log in to comment
this is an enhancement, that you'd like query() to intelligently interpret a relation().
But the documented way to do this is:
additionally its unclear if query(Employee, Employee.company) should automatically "join" the two tables together. Once again, there is a clear method for this already:
So I think the best behavior here would be for query(some_relation()) to just raise an error.