]> 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:12:55 +0000 (09:12 -0400)
committerMike Bayer <mike_mp@zzzcomputing.com>
Wed, 28 Sep 2011 13:12:55 +0000 (09:12 -0400)
be ignored in the "inner" query within a
subquery eager load.  [ticket:2287].

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

diff --git a/CHANGES b/CHANGES
index b06899297eab326447e9caaf6ed65dcf10fad932..6d27cc2e85c639c01664699c657d2bdec536decd 100644 (file)
--- a/CHANGES
+++ b/CHANGES
@@ -32,6 +32,10 @@ CHANGES
     table would convert the lead entity into the 
     joined one inappropriately.  [ticket:2234]
 
+  - Fixed bug whereby mapper.order_by attribute would
+    be ignored in the "inner" query within a 
+    subquery eager load.  [ticket:2287].
+
   - Fixed bug whereby if a mapped class
     redefined __hash__() or __eq__() to something
     non-standard, which is a supported use case
index ac49d335d95411d214cc8ee779703c1b838ad1dc..677b5f862131fd97b5cfe8fc1c482de9086d3a5e 100644 (file)
@@ -776,6 +776,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
@@ -828,6 +831,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 f58ebc8c6c61cd57893b082462b35ad3a3b89189..2cca51f85c90370bddb9f0550ee0a81f4e207813 100644 (file)
@@ -545,6 +545,22 @@ 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)
 
+    @testing.resolve_artifact_names
+    def test_mapper_order_by(self):
+
+        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])))
+
     @testing.resolve_artifact_names
     def test_one_to_many_scalar(self):
         mapper(User, users, properties = dict(