diff options
| -rw-r--r-- | CHANGES | 5 | ||||
| -rw-r--r-- | lib/sqlalchemy/ext/declarative.py | 16 |
2 files changed, 13 insertions, 8 deletions
@@ -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 3b4880403..0fec835ed 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. |
