]> git.ipfire.org Git - thirdparty/sqlalchemy/sqlalchemy.git/commitdiff
merged r6314 of trunk for [ticket:1507]
authorMike Bayer <mike_mp@zzzcomputing.com>
Tue, 1 Sep 2009 22:43:39 +0000 (22:43 +0000)
committerMike Bayer <mike_mp@zzzcomputing.com>
Tue, 1 Sep 2009 22:43:39 +0000 (22:43 +0000)
CHANGES
lib/sqlalchemy/orm/dependency.py
test/orm/test_relationships.py

diff --git a/CHANGES b/CHANGES
index bfae7b8093edf099434c487c6e94bfd5cbff6253..d7478f9e863387aa72c559fd188f46bb55332f49 100644 (file)
--- a/CHANGES
+++ b/CHANGES
@@ -9,7 +9,11 @@ CHANGES
     - Fixed bug whereby inheritance discriminator part of a
       composite primary key would fail on updates.
       Continuation of [ticket:1300].
-    
+
+    - Fixed bug which disallowed one side of a many-to-many 
+      bidirectional reference to declare itself as "viewonly"
+      [ticket:1507]
+
     - Fixed an obscure issue whereby a joined-table subclass
       with a self-referential eager load on the base class
       would populate the related object's "subclass" table with
@@ -77,7 +81,7 @@ CHANGES
       in query.join() which would fail to issue correctly
       if the query was against a pure SQL construct.
       [ticket:1522]
-      
+    
     - Fixed a somewhat hypothetical issue which would result
       in the wrong primary key being calculated for a mapper
       using the old polymorphic_union function - but this
index f3820eb7cdae0b113584aa00f584d227ef1d2488..e17f4bba5500dee7219b72d06e29f7654f44bdac 100644 (file)
@@ -140,7 +140,7 @@ class DependencyProcessor(object):
         
         """
         for r in self.prop._reverse_property:
-            if (r._dependency_processor, action, parent, child) in uowcommit.attributes:
+            if not r.viewonly and (r._dependency_processor, action, parent, child) in uowcommit.attributes:
                 return True
         return False
     
index fef1577f0757c5e3e334d1b84732e329b315eae9..604907f6bef69e17c52cbadc27e72cc67a8ef068 100644 (file)
@@ -1109,7 +1109,44 @@ class TypedAssociationTable(_base.MappedTest):
 
         assert t3.count().scalar() == 1
 
+class ViewOnlyM2MBackrefTest(_base.MappedTest):
+    @classmethod
+    def define_tables(cls, metadata):
+        Table("t1", metadata,
+            Column('id', Integer, primary_key=True, test_needs_autoincrement=True),
+            Column('data', String(40)))
+        Table("t2", metadata,
+            Column('id', Integer, primary_key=True, test_needs_autoincrement=True),
+            Column('data', String(40)),
+        )
+        Table("t1t2", metadata,
+            Column('t1id', Integer, ForeignKey('t1.id'), primary_key=True),
+            Column('t2id', Integer, ForeignKey('t2.id'), primary_key=True),
+        )
+    
+    @testing.resolve_artifact_names
+    def test_viewonly(self):
+        class A(_base.ComparableEntity):pass
+        class B(_base.ComparableEntity):pass
+        
+        mapper(A, t1, properties={
+            'bs':relation(B, secondary=t1t2, backref=backref('as_', viewonly=True))
+        })
+        mapper(B, t2)
+        
+        sess = create_session()
+        a1 = A()
+        b1 = B(as_=[a1])
 
+        sess.add(a1)
+        sess.flush()
+        eq_(
+            sess.query(A).first(), A(bs=[B(id=b1.id)])
+        )
+        eq_(
+            sess.query(B).first(), B(as_=[A(id=a1.id)])
+        )
+        
 class ViewOnlyOverlappingNames(_base.MappedTest):
     """'viewonly' mappings with overlapping PK column names."""