summaryrefslogtreecommitdiff
path: root/lib/sqlalchemy/ext/declarative.py
diff options
context:
space:
mode:
authorMike Bayer <mike_mp@zzzcomputing.com>2008-05-02 01:02:23 +0000
committerMike Bayer <mike_mp@zzzcomputing.com>2008-05-02 01:02:23 +0000
commite3460573d037e27592995277a19840be13457828 (patch)
tree90fbd43479edb50e2cdc12f40fa90bc5368ed846 /lib/sqlalchemy/ext/declarative.py
parentc407a608c38a8d483e77fb950b21995b16fa05f7 (diff)
downloadsqlalchemy-e3460573d037e27592995277a19840be13457828.tar.gz
- factored out the logic used by Join to create its join condition
- With declarative, joined table inheritance mappers use a slightly relaxed function to create the "inherit condition" to the parent table, so that other foreign keys to not-yet-declared Table objects don't trigger an error.
Diffstat (limited to 'lib/sqlalchemy/ext/declarative.py')
-rw-r--r--lib/sqlalchemy/ext/declarative.py9
1 files changed, 8 insertions, 1 deletions
diff --git a/lib/sqlalchemy/ext/declarative.py b/lib/sqlalchemy/ext/declarative.py
index 5bdd9652e..d736736e9 100644
--- a/lib/sqlalchemy/ext/declarative.py
+++ b/lib/sqlalchemy/ext/declarative.py
@@ -187,6 +187,7 @@ from sqlalchemy.orm import synonym as _orm_synonym, mapper, comparable_property
from sqlalchemy.orm.interfaces import MapperProperty
from sqlalchemy.orm.properties import PropertyLoader, ColumnProperty
from sqlalchemy import util, exceptions
+from sqlalchemy.sql import util as sql_util
__all__ = ['declarative_base', 'synonym_for', 'comparable_using',
@@ -241,7 +242,13 @@ class DeclarativeMeta(type):
if 'inherits' not in mapper_args:
inherits = cls.__mro__[1]
inherits = cls._decl_class_registry.get(inherits.__name__, None)
- mapper_args['inherits'] = inherits
+ if inherits:
+ mapper_args['inherits'] = inherits
+ if not mapper_args.get('concrete', False) 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(inherits.__table__, table, ignore_nonexistent_tables=True)
if hasattr(cls, '__mapper_cls__'):
mapper_cls = util.unbound_method_to_callable(cls.__mapper_cls__)