]> git.ipfire.org Git - thirdparty/sqlalchemy/sqlalchemy.git/commitdiff
restored comparison of 1-element clause list -> ClauseElement, which was broken in...
authorMike Bayer <mike_mp@zzzcomputing.com>
Sun, 20 May 2007 18:16:10 +0000 (18:16 +0000)
committerMike Bayer <mike_mp@zzzcomputing.com>
Sun, 20 May 2007 18:16:10 +0000 (18:16 +0000)
lib/sqlalchemy/sql.py
test/orm/mapper.py

index 35cd30b30415d807d170c1c5358724240c3fe2d7..9a93474dc7b6d63f3f89e3447c44f14978b1ef6f 100644 (file)
@@ -1964,7 +1964,9 @@ class ClauseList(ClauseElement):
         including a comparison of all the clause items.
         """
 
-        if isinstance(other, ClauseList) and len(self.clauses) == len(other.clauses):
+        if not isinstance(other, ClauseList) and len(self.clauses) == 1:
+            return self.clauses[0].compare(other)
+        elif isinstance(other, ClauseList) and len(self.clauses) == len(other.clauses):
             for i in range(0, len(self.clauses)):
                 if not self.clauses[i].compare(other.clauses[i]):
                     return False
index 5c4efb6a9c5dad0db7c0bc9962cdbca6303f9761..889a7c925972c896ae04a8224cf2e87aac9a111c 100644 (file)
@@ -1087,6 +1087,22 @@ class LazyTest(MapperSuperTest):
         self.echo(repr(l[0].user))
         self.assert_(l[0].user is not None)
 
+    def testuseget(self):
+        """test that a simple many-to-one lazyload optimizes to use query.get().
+        
+        this is done currently by comparing the 'get' SQL clause of the query
+        to the 'lazy' SQL clause of the lazy loader, so it relies heavily on 
+        ClauseElement.compare()"""
+        
+        m = mapper(Address, addresses, properties = dict(
+            user = relation(mapper(User, users), lazy = True)
+        ))
+        sess = create_session()
+        a1 = sess.query(Address).get_by(email_address = "ed@wood.com")
+        u1 = sess.query(User).get(8)
+        def go():
+            assert a1.user is u1
+        self.assert_sql_count(db, go, 0)
 
     def testdouble(self):
         """tests lazy loading with two relations simulatneously, from the same table, using aliases.  """