]> git.ipfire.org Git - thirdparty/sqlalchemy/sqlalchemy.git/commitdiff
- Can now use a custom "inherit_condition" in
authorMike Bayer <mike_mp@zzzcomputing.com>
Wed, 12 Nov 2008 15:43:17 +0000 (15:43 +0000)
committerMike Bayer <mike_mp@zzzcomputing.com>
Wed, 12 Nov 2008 15:43:17 +0000 (15:43 +0000)
__mapper_args__ when using declarative.

CHANGES
lib/sqlalchemy/ext/declarative.py
test/ext/declarative.py

diff --git a/CHANGES b/CHANGES
index ecb85e60ef59e00648da67c78b7be6a8acfbc49a..b9d2c1bbef2db49a97bc22de5e9b06d1ec23a4f8 100644 (file)
--- 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
index b7ae47edf99d26270770a1a3ef2582a69b1f0ef5..a2615684492374cd9d6942f5fe39fba7b3877713 100644 (file)
@@ -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
index 1c088d143417e81c2ac7fd0b00b688971a283e27..13de2f2469ebe79a3592c9acef6122056df6ed28 100644 (file)
@@ -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'