From: Mike Bayer Date: Wed, 12 Nov 2008 15:43:17 +0000 (+0000) Subject: - Can now use a custom "inherit_condition" in X-Git-Tag: rel_0_5rc4~7 X-Git-Url: http://git.ipfire.org/cgi-bin/gitweb.cgi?a=commitdiff_plain;h=0148adec3069c64f3dca8d269e4c0fac3fe6bcaf;p=thirdparty%2Fsqlalchemy%2Fsqlalchemy.git - Can now use a custom "inherit_condition" in __mapper_args__ when using declarative. --- diff --git a/CHANGES b/CHANGES index ecb85e60ef..b9d2c1bbef 100644 --- a/CHANGES +++ b/CHANGES @@ -29,7 +29,7 @@ CHANGES - Adjustments to the enhanced garbage collection on InstanceState to better guard against errors due to lost state. - + - Query.get() returns a more informative error message when executed against multiple entities. [ticket:1220] @@ -68,6 +68,10 @@ CHANGES schemas, particularly when those schemas are the default schema. [ticket:1217] +- ext + - Can now use a custom "inherit_condition" in + __mapper_args__ when using declarative. + 0.5.0rc3 ======== - features diff --git a/lib/sqlalchemy/ext/declarative.py b/lib/sqlalchemy/ext/declarative.py index b7ae47edf9..a261568449 100644 --- a/lib/sqlalchemy/ext/declarative.py +++ b/lib/sqlalchemy/ext/declarative.py @@ -311,7 +311,7 @@ def _as_declarative(cls, classname, dict_): inherits = cls._decl_class_registry.get(inherits.__name__, None) if inherits: mapper_args['inherits'] = inherits - if not mapper_args.get('concrete', False) and table: + if not mapper_args.get('concrete', False) and table and 'inherit_condition' not in mapper_args: # figure out the inherit condition with relaxed rules # about nonexistent tables, to allow for ForeignKeys to # not-yet-defined tables (since we know for sure that our diff --git a/test/ext/declarative.py b/test/ext/declarative.py index 1c088d1434..13de2f2469 100644 --- a/test/ext/declarative.py +++ b/test/ext/declarative.py @@ -536,6 +536,20 @@ class DeclarativeTest(testing.TestBase, testing.AssertsExecutionResults): sess.flush() eq_(sess.query(User).filter(User.name == "SOMENAME someuser").one(), u1) + def test_custom_inh(self): + class Foo(Base): + __tablename__ = 'foo' + id = Column('id', Integer, primary_key=True) + + class Bar(Foo): + __tablename__ = 'bar' + id = Column('id', Integer, primary_key=True) + foo_id = Column('foo_id', Integer) + __mapper_args__ = {'inherit_condition':foo_id==Foo.id} + + # compile succeeds because inherit_condition is honored + compile_mappers() + def test_joined_inheritance(self): class Company(Base, ComparableEntity): __tablename__ = 'companies'