summaryrefslogtreecommitdiff
path: root/test/orm/query.py
diff options
context:
space:
mode:
authorMike Bayer <mike_mp@zzzcomputing.com>2009-01-06 04:30:11 +0000
committerMike Bayer <mike_mp@zzzcomputing.com>2009-01-06 04:30:11 +0000
commitd14317fd7a05be0ec4586981e8875ae563558f81 (patch)
tree5574a7bf1bf37c16bb98313a977c850afd00d3ff /test/orm/query.py
parente1401bd28e5d127ef1c079b5426be37d63ab0157 (diff)
downloadsqlalchemy-d14317fd7a05be0ec4586981e8875ae563558f81.tar.gz
- query.join() raises an error when the target of the join
doesn't match the property-based attribute - while it's unlikely anyone is doing this, the SQLAlchemy author was guilty of this particular loosey-goosey behavior.
Diffstat (limited to 'test/orm/query.py')
-rw-r--r--test/orm/query.py32
1 files changed, 32 insertions, 0 deletions
diff --git a/test/orm/query.py b/test/orm/query.py
index b446c1ae5..cba57914d 100644
--- a/test/orm/query.py
+++ b/test/orm/query.py
@@ -979,6 +979,38 @@ class JoinTest(QueryTest):
[]
)
+ def test_backwards_join(self):
+ # a more controversial feature. join from
+ # User->Address, but the onclause is Address.user.
+
+ sess = create_session()
+
+ self.assertEquals(
+ sess.query(User).join(Address.user).filter(Address.email_address=='ed@wood.com').all(),
+ [User(id=8,name=u'ed')]
+ )
+
+ # its actually not so controversial if you view it in terms
+ # of multiple entities.
+ self.assertEquals(
+ sess.query(User, Address).join(Address.user).filter(Address.email_address=='ed@wood.com').all(),
+ [(User(id=8,name=u'ed'), Address(email_address='ed@wood.com'))]
+ )
+
+ # this was the controversial part. now, raise an error if the feature is abused.
+ # before the error raise was added, this would silently work.....
+ self.assertRaises(
+ sa_exc.InvalidRequestError,
+ sess.query(User).join, (Address, Address.user),
+ )
+
+ # but this one would silently fail
+ adalias = aliased(Address)
+ self.assertRaises(
+ sa_exc.InvalidRequestError,
+ sess.query(User).join, (adalias, Address.user),
+ )
+
def test_multiple_with_aliases(self):
sess = create_session()