]> git.ipfire.org Git - thirdparty/sqlalchemy/sqlalchemy.git/commitdiff
PropertyLoader will not re-determine direction when initialized a second time, as...
authorMike Bayer <mike_mp@zzzcomputing.com>
Sat, 18 Mar 2006 00:12:59 +0000 (00:12 +0000)
committerMike Bayer <mike_mp@zzzcomputing.com>
Sat, 18 Mar 2006 00:12:59 +0000 (00:12 +0000)
lib/sqlalchemy/mapping/properties.py
test/inheritance.py

index e5f702b578c7acc350dcf75d8a07a149c4153a8c..6b8c137930c5d7e0061408a6b8ad693203adde00 100644 (file)
@@ -118,6 +118,7 @@ class PropertyLoader(MapperProperty):
         self.primaryjoin = primaryjoin
         self.secondaryjoin = secondaryjoin
         self.post_update = post_update
+        self.direction = None
         
         # would like to have foreignkey be a list.
         # however, have to figure out how to do 
@@ -186,7 +187,10 @@ class PropertyLoader(MapperProperty):
             # but its possible that its reversed
             self._find_dependent()
 
-        self.direction = self._get_direction()
+        # if we are re-initializing, as in a copy made for an inheriting 
+        # mapper, dont re-evaluate the direction.
+        if self.direction is None:
+            self.direction = self._get_direction()
         
         if self.uselist is None and self.direction == PropertyLoader.MANYTOONE:
             self.uselist = False
index 71cc78882ee6aeabf0dbc80049b775f3362dc916..a3a354c5adf59f55e44b7f6e949bd025c5e4be67 100644 (file)
@@ -351,5 +351,39 @@ class InheritTest4(testbase.AssertMixin):
         self.assert_(compare == result)
         self.assert_(l[0].parent_foo.data == 'foo #1' and l[1].parent_foo.data == 'foo #1')
 
+class InheritTest5(testbase.AssertMixin): 
+    def setUpAll(self):
+        engine = testbase.db
+        global content_type, content, product
+        content_type = Table('content_type', engine, 
+            Column('id', Integer, primary_key=True)
+            )
+        content = Table('content', engine,
+            Column('id', Integer, primary_key=True),
+            Column('content_type_id', Integer, ForeignKey('content_type.id'))
+            )
+        product = Table('product', engine, 
+            Column('id', Integer, ForeignKey('content.id'), primary_key=True)
+        )
+    def tearDownAll(self):
+        testbase.db.tables.clear()
+
+    def tearDown(self):
+        pass
+
+    def testbasic(self):
+        class ContentType(object): pass
+        class Content(object): pass
+        class Product(object): pass
+
+        content_types = mapper(ContentType, content_type)
+        contents = mapper(Content, content, properties={
+            'content_type':relation(content_types)
+        })
+        #contents.add_property('content_type', relation(content_types)) #adding this makes the inheritance stop working
+        # shouldnt throw exception
+        products = mapper(Product, product, inherits=contents)
+        
+
 if __name__ == "__main__":    
     testbase.main()