]> git.ipfire.org Git - thirdparty/sqlalchemy/sqlalchemy.git/commitdiff
- fixed bug in query.instances() that wouldnt handle more than
authorMike Bayer <mike_mp@zzzcomputing.com>
Sun, 20 May 2007 16:40:21 +0000 (16:40 +0000)
committerMike Bayer <mike_mp@zzzcomputing.com>
Sun, 20 May 2007 16:40:21 +0000 (16:40 +0000)
on additional mapper or one additional column.

CHANGES
lib/sqlalchemy/orm/query.py
test/orm/mapper.py

diff --git a/CHANGES b/CHANGES
index 3dab91e901f223692df3301001607a59cd8b4e8f..e7938bdc8579411a7f66e70c8e0f8f382de8fbd9 100644 (file)
--- a/CHANGES
+++ b/CHANGES
@@ -20,6 +20,8 @@
     - removed "no group by's in a select thats part of a UNION"
       restriction [ticket:578]
 - orm
+    - fixed bug in query.instances() that wouldnt handle more than
+      on additional mapper or one additional column.
     - "delete-orphan" no longer implies "delete". ongoing effort to 
       separate the behavior of these two operations.
     - many-to-many relationships properly set the type of bind params
index 38279f5f210b03272a7ade4901036cfeeb503ae4..74d4ceed71cb8d7f0513dfb50a9dd165acaf133a 100644 (file)
@@ -882,16 +882,20 @@ class Query(object):
                 if isinstance(m, type):
                     m = mapper.class_mapper(m)
                 if isinstance(m, mapper.Mapper):
-                    appender = []
-                    def proc(context, row):
-                        if not m._instance(context, row, appender):
-                            appender.append(None)
-                    process.append((proc, appender))
+                    def x(m):
+                        appender = []
+                        def proc(context, row):
+                            if not m._instance(context, row, appender):
+                                appender.append(None)
+                        process.append((proc, appender))
+                    x(m)
                 elif isinstance(m, sql.ColumnElement) or isinstance(m, basestring):
-                    res = []
-                    def proc(context, row):
-                        res.append(row[m])
-                    process.append((proc, res))
+                    def y(m):
+                        res = []
+                        def proc(context, row):
+                            res.append(row[m])
+                        process.append((proc, res))
+                    y(m)
             result = []
         else:
             result = util.UniqueAppender([])
index 4ce1be2fa762aeb56d15784137a979787d86f8ef..5c4efb6a9c5dad0db7c0bc9962cdbca6303f9761 100644 (file)
@@ -1619,6 +1619,20 @@ class InstancesTest(MapperSuperTest):
             (user8, 3),
             (user9, 0)
         ]
+        
+    def testmappersplustwocolumns(self):
+        mapper(User, users)
+        s = select([users, func.count(addresses.c.address_id).label('count'), ("Name:" + users.c.user_name).label('concat')], from_obj=[users.outerjoin(addresses)], group_by=[c for c in users.c], order_by=[users.c.user_id])
+        sess = create_session()
+        (user7, user8, user9) = sess.query(User).select()
+        q = sess.query(User)
+        l = q.instances(s.execute(), "count", "concat")
+        print l
+        assert l == [
+            (user7, 1, "Name:jack"),
+            (user8, 3, "Name:ed"),
+            (user9, 0, "Name:fred")
+        ]
 
 
 if __name__ == "__main__":