]> git.ipfire.org Git - thirdparty/sqlalchemy/sqlalchemy.git/commitdiff
test graceful fallback to lazy loading for cyclical eager load with no join_depth
authorMike Bayer <mike_mp@zzzcomputing.com>
Tue, 24 Jul 2007 22:31:46 +0000 (22:31 +0000)
committerMike Bayer <mike_mp@zzzcomputing.com>
Tue, 24 Jul 2007 22:31:46 +0000 (22:31 +0000)
test/orm/eager_relations.py

index 49ea65153be3aaa793d0c1bb22bcea64cb1cf4aa..a109be56f08890f46bbf415d6f42f80474453283 100644 (file)
@@ -478,5 +478,37 @@ class SelfReferentialEagerTest(ORMTest):
             ]) == d
         self.assert_sql_count(testbase.db, go, 1)
 
+    def test_no_depth(self):
+        class Node(Base):
+            def append(self, node):
+                self.children.append(node)
+
+        mapper(Node, nodes, properties={
+            'children':relation(Node, lazy=False)
+        })
+        sess = create_session()
+        n1 = Node(data='n1')
+        n1.append(Node(data='n11'))
+        n1.append(Node(data='n12'))
+        n1.append(Node(data='n13'))
+        n1.children[1].append(Node(data='n121'))
+        n1.children[1].append(Node(data='n122'))
+        n1.children[1].append(Node(data='n123'))
+        sess.save(n1)
+        sess.flush()
+        sess.clear()
+        def go():
+            d = sess.query(Node).filter_by(data='n1').first()
+            assert Node(data='n1', children=[
+                Node(data='n11'),
+                Node(data='n12', children=[
+                    Node(data='n121'),
+                    Node(data='n122'),
+                    Node(data='n123')
+                ]),
+                Node(data='n13')
+            ]) == d
+        self.assert_sql_count(testbase.db, go, 3)
+
 if __name__ == '__main__':
     testbase.main()