Commits

Mike Bayer committed 6e468f2

fixed further issues with row translation [ticket:868]

  • Participants
  • Parent commits 4d3911e

Comments (0)

Files changed (2)

File lib/sqlalchemy/orm/util.py

         def __init__(self, row):
             self.row = row
         def __contains__(self, key):
-            return key in self.row or (key in map and map[key] in self.row)
+            if key in map:
+                return map[key] in self.row
+            else:
+                return key in self.row
         def has_key(self, key):
             return key in self
         def __getitem__(self, key):

File test/orm/eager_relations.py

             ]) == d
         self.assert_sql_count(testbase.db, go, 1)
 
+    def test_with_deferred(self):
+        class Node(Base):
+            def append(self, node):
+                self.children.append(node)
+
+        mapper(Node, nodes, properties={
+            'children':relation(Node, lazy=False, join_depth=3),
+            'data':deferred(nodes.c.data)
+        })
+        sess = create_session()
+        n1 = Node(data='n1')
+        n1.append(Node(data='n11'))
+        n1.append(Node(data='n12'))
+        sess.save(n1)
+        sess.flush()
+        sess.clear()
+
+        def go():
+            assert Node(data='n1', children=[Node(data='n11'), Node(data='n12')]) == sess.query(Node).first()
+        self.assert_sql_count(testbase.db, go, 4)
+        
+        sess.clear()
+
+        def go():
+            assert Node(data='n1', children=[Node(data='n11'), Node(data='n12')]) == sess.query(Node).options(undefer('data')).first()
+        self.assert_sql_count(testbase.db, go, 3)
+
+        sess.clear()
+        
+        def go():
+            assert Node(data='n1', children=[Node(data='n11'), Node(data='n12')]) == sess.query(Node).options(undefer('data'), undefer('children.data')).first()
+        self.assert_sql_count(testbase.db, go, 1)
+        
+        
+        
     def test_options(self):
         class Node(Base):
             def append(self, node):