]> git.ipfire.org Git - thirdparty/sqlalchemy/sqlalchemy.git/commitdiff
- Fixed bug whereby mapper.order_by attribute would
authorMike Bayer <mike_mp@zzzcomputing.com>
Wed, 28 Sep 2011 13:10:23 +0000 (09:10 -0400)
committerMike Bayer <mike_mp@zzzcomputing.com>
Wed, 28 Sep 2011 13:10:23 +0000 (09:10 -0400)
be ignored in the "inner" query within a
subquery eager load.  [ticket:2287].
Also in 0.6.9.

CHANGES
lib/sqlalchemy/orm/strategies.py
test/orm/test_subquery_relations.py

diff --git a/CHANGES b/CHANGES
index d4b8bf33871c9b00644ccced68f4556da3c99c05..cbe87341bae7b06db0ebd1f6dd853c5e707901b7 100644 (file)
--- a/CHANGES
+++ b/CHANGES
@@ -48,6 +48,11 @@ CHANGES
           to query.options(), passed by name
           to query.with_parent().
 
+  - Fixed bug whereby mapper.order_by attribute would
+    be ignored in the "inner" query within a 
+    subquery eager load.  [ticket:2287].
+    Also in 0.6.9.
+
   - Identity map .discard() uses dict.pop(,None) 
     internally instead of "del" to avoid KeyError/warning 
     during a non-determinate gc teardown [ticket:2267]
index c335d1509af82b68a122bca9e958ebd5fc541976..fa722b72536f2e42d4326b37fede78d884c3e88f 100644 (file)
@@ -748,6 +748,9 @@ class SubqueryLoader(AbstractRelationshipLoader):
         # with polymorphic loading ?
         q._set_entities(q._adapt_col_list(leftmost_attr))
 
+        if q._order_by is False:
+            q._order_by = leftmost_mapper.order_by
+
         # don't need ORDER BY if no limit/offset
         if q._limit is None and q._offset is None:
             q._order_by = None
@@ -800,6 +803,7 @@ class SubqueryLoader(AbstractRelationshipLoader):
             getattr(parent_alias, self.parent._columntoproperty[c].key)
             for c in local_cols
         ]
+
         q = q.order_by(*local_attr)
         q = q.add_columns(*local_attr)
 
index 8673211f8b62d1262a474d8b201a850642c531a5..d309a951246d5387e13539173805ccda6c3c1d9f 100644 (file)
@@ -671,6 +671,26 @@ class EagerTest(_fixtures.FixtureTest, testing.AssertsCompiledSQL):
         l = q.order_by(sa.desc(User.id)).limit(2).offset(2).all()
         eq_(list(reversed(self.static.user_all_result[0:2])), l)
 
+    def test_mapper_order_by(self):
+        users, User, Address, addresses = (self.tables.users,
+                                self.classes.User,
+                                self.classes.Address,
+                                self.tables.addresses)
+
+        mapper(Address, addresses)
+        mapper(User, users, properties={
+            'addresses':relationship(Address,
+                            lazy='subquery',
+                            order_by=addresses.c.id),
+        },order_by=users.c.id.desc())
+
+        sess = create_session()
+        q = sess.query(User)
+
+        l = q.limit(2).all()
+        eq_(l, list(reversed(self.static.user_address_result[2:4])))
+
+
     def test_one_to_many_scalar(self):
         Address, addresses, users, User = (self.classes.Address,
                                 self.tables.addresses,