summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorMike Bayer <mike_mp@zzzcomputing.com>2008-11-12 15:43:17 +0000
committerMike Bayer <mike_mp@zzzcomputing.com>2008-11-12 15:43:17 +0000
commit0148adec3069c64f3dca8d269e4c0fac3fe6bcaf (patch)
tree3c51cb7bc367da1299ac800f027ccc242e949ad7
parent260c201f656ce3afe35f9ae069cdf46593d4dffb (diff)
downloadsqlalchemy-0148adec3069c64f3dca8d269e4c0fac3fe6bcaf.tar.gz
- Can now use a custom "inherit_condition" in
__mapper_args__ when using declarative.
-rw-r--r--CHANGES6
-rw-r--r--lib/sqlalchemy/ext/declarative.py2
-rw-r--r--test/ext/declarative.py14
3 files changed, 20 insertions, 2 deletions
diff --git a/CHANGES b/CHANGES
index ecb85e60e..b9d2c1bbe 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 b7ae47edf..a26156844 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 1c088d143..13de2f246 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'