]> git.ipfire.org Git - thirdparty/sqlalchemy/sqlalchemy.git/commitdiff
- Declarative figures out joined-table inheritance primary join
authorMike Bayer <mike_mp@zzzcomputing.com>
Mon, 16 Feb 2009 23:49:53 +0000 (23:49 +0000)
committerMike Bayer <mike_mp@zzzcomputing.com>
Mon, 16 Feb 2009 23:49:53 +0000 (23:49 +0000)
condition even if "inherits" mapper argument is given
explicitly.  Allows mixins to be used with joined table
inheritance.

CHANGES
lib/sqlalchemy/ext/declarative.py

diff --git a/CHANGES b/CHANGES
index ae0a2e2ff4930ae9a599b7714c72c888629ab944..d14859960f5484070409118938e6c517affdfdfa 100644 (file)
--- 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
index 3b4880403ae13cca96d8361835cfe75effc6002e..0fec835ed595ca369a352d9eacce0d3e2d0ac905 100644 (file)
@@ -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.