From 5de90720b87b513e1c3ab442ac8befb4bfc41e32 Mon Sep 17 00:00:00 2001 From: Mike Bayer Date: Sat, 18 Mar 2006 00:12:59 +0000 Subject: [PATCH] PropertyLoader will not re-determine direction when initialized a second time, as it is re-initialized as a copy made for an inheriting mapper, and no longer can get to the correct inheriting table. --- lib/sqlalchemy/mapping/properties.py | 6 ++++- test/inheritance.py | 34 ++++++++++++++++++++++++++++ 2 files changed, 39 insertions(+), 1 deletion(-) diff --git a/lib/sqlalchemy/mapping/properties.py b/lib/sqlalchemy/mapping/properties.py index e5f702b578..6b8c137930 100644 --- a/lib/sqlalchemy/mapping/properties.py +++ b/lib/sqlalchemy/mapping/properties.py @@ -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 diff --git a/test/inheritance.py b/test/inheritance.py index 71cc78882e..a3a354c5ad 100644 --- a/test/inheritance.py +++ b/test/inheritance.py @@ -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() -- 2.47.2