]> git.ipfire.org Git - thirdparty/sqlalchemy/sqlalchemy.git/commitdiff
- Fixed bug where many-to-many relation() with
authorMike Bayer <mike_mp@zzzcomputing.com>
Wed, 17 Dec 2008 20:39:18 +0000 (20:39 +0000)
committerMike Bayer <mike_mp@zzzcomputing.com>
Wed, 17 Dec 2008 20:39:18 +0000 (20:39 +0000)
viewonly=True would not correctly reference the
link between secondary->remote.

CHANGES
lib/sqlalchemy/orm/properties.py
test/orm/relationships.py

diff --git a/CHANGES b/CHANGES
index 14b58b41a24e0b20d9ffe4347bad2c082765cbe2..4eabb400934fb40fc52bdd37d8ec8a2d2145106a 100644 (file)
--- a/CHANGES
+++ b/CHANGES
@@ -57,6 +57,10 @@ CHANGES
       added to a mapper post-compile using 
       add_property() or equivalent.
 
+    - Fixed bug where many-to-many relation() with
+      viewonly=True would not correctly reference the
+      link between secondary->remote.
+      
     - Duplicate items in a list-based collection will
       be maintained when issuing INSERTs to
       a "secondary" table in a many-to-many relation.
index 87ad6819e335b1e19bf7791d71738770b2687037..93fae08379dc9146b830e01202035e3671f68e6b 100644 (file)
@@ -793,6 +793,8 @@ class RelationProperty(StrategizedProperty):
             else:
                 if self.viewonly:
                     eq_pairs = self.synchronize_pairs
+                    if self.secondaryjoin:
+                        eq_pairs += self.secondary_synchronize_pairs
                 else:
                     eq_pairs = criterion_as_pairs(self.primaryjoin, consider_as_foreign_keys=self._foreign_keys, any_operator=True)
                     if self.secondaryjoin:
index 22665f99064dd5c12455b9235a813566d43e4b54..181ed375cefd832943740f32f26e1f0b4d6c3a4f 100644 (file)
@@ -1004,7 +1004,38 @@ class ViewOnlyUniqueNames(_base.MappedTest):
         assert set([x.t2id for x in c1.t2s]) == set([c2a.t2id, c2b.t2id])
         assert set([x.t2id for x in c1.t2_view]) == set([c2b.t2id])
 
+class ViewOnlyLocalRemoteM2M(testing.TestBase):
+    """test that local-remote is correctly determined for m2m"""
+    
+    def test_local_remote(self):
+        meta = MetaData()
+        
+        t1 = Table('t1', meta,
+                Column('id', Integer, primary_key=True),
+            )
+        t2 = Table('t2', meta,
+                Column('id', Integer, primary_key=True),
+            )
+        t12 = Table('tab', meta,
+                Column('t1_id', Integer, ForeignKey('t1.id',)),
+                Column('t2_id', Integer, ForeignKey('t2.id',)),
+            )
+        
+        class A(object): pass
+        class B(object): pass
+        mapper( B, t2, )
+        m = mapper( A, t1, properties=dict(
+                b_view = relation( B, secondary=t12, viewonly=True),
+                b_plain= relation( B, secondary=t12),
+            )
+        )
+        compile_mappers()
+        assert m.get_property('b_view').local_remote_pairs == \
+            m.get_property('b_plain').local_remote_pairs == \
+            [(t1.c.id, t12.c.t1_id), (t12.c.t2_id, t2.c.id)]
 
+        
+    
 class ViewOnlyNonEquijoin(_base.MappedTest):
     """'viewonly' mappings based on non-equijoins."""