From: Mike Bayer Date: Mon, 16 Feb 2009 23:49:53 +0000 (+0000) Subject: - Declarative figures out joined-table inheritance primary join X-Git-Tag: rel_0_5_3~28 X-Git-Url: http://git.ipfire.org/gitweb/gitweb.cgi?a=commitdiff_plain;h=e329fb31782123fb3fbc840a6f551a67213c5d17;p=thirdparty%2Fsqlalchemy%2Fsqlalchemy.git - Declarative figures out joined-table inheritance primary join condition even if "inherits" mapper argument is given explicitly. Allows mixins to be used with joined table inheritance. --- diff --git a/CHANGES b/CHANGES index ae0a2e2ff4..d14859960f 100644 --- a/CHANGES +++ b/CHANGES @@ -53,6 +53,11 @@ CHANGES "committed" state, i.e. state that is understood to have been loaded from the database. Helps with the creation of homegrown collection loaders and such. + + - Declarative figures out joined-table inheritance primary join + condition even if "inherits" mapper argument is given + explicitly. Allows mixins to be used with joined table + inheritance. - sql - Fixed missing _label attribute on Function object, others diff --git a/lib/sqlalchemy/ext/declarative.py b/lib/sqlalchemy/ext/declarative.py index 3b4880403a..0fec835ed5 100644 --- a/lib/sqlalchemy/ext/declarative.py +++ b/lib/sqlalchemy/ext/declarative.py @@ -487,14 +487,6 @@ 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 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 - # parent table is defined within the same MetaData) - mapper_args['inherit_condition'] = sql_util.join_condition( - inherits.__table__, table, - ignore_nonexistent_tables=True) if hasattr(cls, '__mapper_cls__'): mapper_cls = util.unbound_method_to_callable(cls.__mapper_cls__) @@ -508,6 +500,14 @@ def _as_declarative(cls, classname, dict_): elif 'inherits' in mapper_args and not mapper_args.get('concrete', False): inherited_mapper = class_mapper(mapper_args['inherits'], compile=False) inherited_table = inherited_mapper.local_table + if 'inherit_condition' not in mapper_args and table: + # 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 + # parent table is defined within the same MetaData) + mapper_args['inherit_condition'] = sql_util.join_condition( + mapper_args['inherits'].__table__, table, + ignore_nonexistent_tables=True) if not table: # single table inheritance.