]> git.ipfire.org Git - thirdparty/sqlalchemy/sqlalchemy.git/commitdiff
- Lazy loader will not use get() if the "lazy load"
authorMike Bayer <mike_mp@zzzcomputing.com>
Sun, 29 Mar 2009 21:21:10 +0000 (21:21 +0000)
committerMike Bayer <mike_mp@zzzcomputing.com>
Sun, 29 Mar 2009 21:21:10 +0000 (21:21 +0000)
SQL clause matches the clause used by get(), but
contains some parameters hardcoded.  Previously
the lazy strategy would fail with the get().  Ideally
get() would be used with the hardcoded parameters
but this would require further development.
[ticket:1357]

CHANGES
lib/sqlalchemy/sql/expression.py
test/orm/lazy_relations.py
test/sql/select.py

diff --git a/CHANGES b/CHANGES
index b6d9dae3e525a125958aa262c673f7d62e612bf5..8aa1709c6e8b9215def8955ebc512fa50f541f1f 100644 (file)
--- a/CHANGES
+++ b/CHANGES
@@ -13,6 +13,14 @@ CHANGES
       Set collection is now compatible with merge(), 
       fixes [ticket:1352].
 
+    - Lazy loader will not use get() if the "lazy load"
+      SQL clause matches the clause used by get(), but
+      contains some parameters hardcoded.  Previously
+      the lazy strategy would fail with the get().  Ideally
+      get() would be used with the hardcoded parameters
+      but this would require further development.
+      [ticket:1357]
+
 - sql
     - Fixed __repr__() and other _get_colspec() methods on 
       ForeignKey constructed from __clause_element__() style
index f94e849e5696a7bc7d3b9a29582833fb36845898..5a0d5b04309b788043af5e023c39b717be322b5d 100644 (file)
@@ -2013,7 +2013,7 @@ class _BindParamClause(ColumnElement):
         the same type.
 
         """
-        return isinstance(other, _BindParamClause) and other.type.__class__ == self.type.__class__
+        return isinstance(other, _BindParamClause) and other.type.__class__ == self.type.__class__ and self.value == other.value
 
     def __getstate__(self):
         """execute a deferred value for serialization purposes."""
index 4ac8a13efcf324473a870c4cdd5624e351380ce3..b5c3b3669eac7ac0060bc5e94fa25aa6616ed213 100644 (file)
@@ -173,6 +173,27 @@ class LazyTest(_fixtures.FixtureTest):
         l = q.filter(users.c.id == 7).all()
         assert [User(id=7, address=Address(id=1))] == l
 
+    @testing.resolve_artifact_names
+    def test_many_to_one_binds(self):
+        mapper(Address, addresses, primary_key=[addresses.c.user_id, addresses.c.email_address])
+        
+        mapper(User, users, properties = dict(
+            address = relation(Address, uselist=False,
+                primaryjoin=sa.and_(users.c.id==addresses.c.user_id, addresses.c.email_address=='ed@bettyboop.com')
+            )
+        ))
+        q = create_session().query(User)
+        eq_(
+            [
+                User(id=7, address=None),
+                User(id=8, address=Address(id=3)),
+                User(id=9, address=None),
+                User(id=10, address=None),
+            ], 
+            list(q)
+        )
+        
+
     @testing.resolve_artifact_names
     def test_double(self):
         """tests lazy loading with two relations simulatneously, from the same table, using aliases.  """
index 5d6d6dcaab211d5c45cad2dac32a53d14eab3242..15c47a6747860278fdfd9465e7c9fc1b03a03dd2 100644 (file)
@@ -404,6 +404,7 @@ sq.myothertable_othername AS sq_myothertable_othername FROM (" + sqstring + ") A
             "myothertable.othername = :othername_2 OR myothertable.otherid = :otherid_1) AND sysdate() = today()",
             checkparams = {'othername_1': 'asdf', 'othername_2':'foo', 'otherid_1': 9, 'myid_1': 12}
         )
+        
 
     def test_distinct(self):
         self.assert_compile(