diff options
author | Mike Bayer <mike_mp@zzzcomputing.com> | 2010-02-23 00:57:08 +0000 |
---|---|---|
committer | Mike Bayer <mike_mp@zzzcomputing.com> | 2010-02-23 00:57:08 +0000 |
commit | bee34dfcd61106ee8eecebd7913efe1904ce5a4a (patch) | |
tree | 3632b19f6118e97a4cc43bc720842b06b57134cd | |
parent | c2060e8943e628404d9620ad60787c6af0a12b07 (diff) | |
download | sqlalchemy-bee34dfcd61106ee8eecebd7913efe1904ce5a4a.tar.gz |
- a change to the previous __mapper_args__ commit.
- the __mapper_args__ dict is copied when propagating to a subclass,
and is taken straight off the class __dict__ to avoid any
propagation from the parent. mapper inheritance already
propagates the things you want from the parent mapper.
[ticket:1393]
-rw-r--r-- | CHANGES | 8 | ||||
-rw-r--r-- | lib/sqlalchemy/ext/declarative.py | 7 | ||||
-rw-r--r-- | test/ext/test_declarative.py | 6 |
3 files changed, 14 insertions, 7 deletions
@@ -166,9 +166,11 @@ CHANGES in theory make it easier for custom metaclasses to modify the state passed into _as_declarative. - - the __mapper_args__ dict is copied when propagating to a subclass. - Still need to decide how the argument propagation should - work in the bigger picture. [ticket:1393] + - the __mapper_args__ dict is copied when propagating to a subclass, + and is taken straight off the class __dict__ to avoid any + propagation from the parent. mapper inheritance already + propagates the things you want from the parent mapper. + [ticket:1393] - mysql - Fixed reflection bug whereby when COLLATE was present, diff --git a/lib/sqlalchemy/ext/declarative.py b/lib/sqlalchemy/ext/declarative.py index cc972fc6f..43177e2e2 100644 --- a/lib/sqlalchemy/ext/declarative.py +++ b/lib/sqlalchemy/ext/declarative.py @@ -499,8 +499,11 @@ def _as_declarative(cls, classname, dict_): if not table.c.contains_column(c): raise exceptions.ArgumentError( "Can't add additional column %r when specifying __table__" % key) - - mapper_args = dict(getattr(cls, '__mapper_args__', {})) + + if '__mapper_args__' in dict_: + mapper_args = dict(dict_['__mapper_args__']) + else: + mapper_args = {} if 'inherits' not in mapper_args: for c in cls.__bases__: if _is_mapped_class(c): diff --git a/test/ext/test_declarative.py b/test/ext/test_declarative.py index ad9972756..4722427d5 100644 --- a/test/ext/test_declarative.py +++ b/test/ext/test_declarative.py @@ -924,13 +924,15 @@ class DeclarativeInheritanceTest(DeclarativeTestBase): __tablename__ = 'people' id = Column(Integer, primary_key=True) discriminator = Column('type', String(50)) - __mapper_args__ = {'polymorphic_on': discriminator} + __mapper_args__ = {'polymorphic_on': discriminator,'polymorphic_identity':'person'} class Engineer(Person): primary_language = Column(String(50)) assert 'inherits' not in Person.__mapper_args__ - + assert class_mapper(Engineer).polymorphic_on is None + + def test_custom_join_condition(self): class Foo(Base): __tablename__ = 'foo' |