]> git.ipfire.org Git - thirdparty/sqlalchemy/sqlalchemy.git/commitdiff
added 'noninherited table' prop to mapper indicating the "lead" table, in the case of
authorMike Bayer <mike_mp@zzzcomputing.com>
Thu, 9 Mar 2006 00:24:15 +0000 (00:24 +0000)
committerMike Bayer <mike_mp@zzzcomputing.com>
Thu, 9 Mar 2006 00:24:15 +0000 (00:24 +0000)
inheritance.  relations now create priamry/secondary joins against that lead table.  if you want to create it against
an inherited table, use explicit join conditions.
added 'correlate' argument to CompoundSelect to get polymorph example working again.

CHANGES
examples/polymorph/polymorph.py
lib/sqlalchemy/mapping/mapper.py
lib/sqlalchemy/mapping/properties.py
lib/sqlalchemy/sql.py
test/inheritance.py

diff --git a/CHANGES b/CHANGES
index 75e88c193cf51c742407ed31730c222df1ba82d4..ed80b46872b1744ff4394f7d3062b3ba84e6c406 100644 (file)
--- a/CHANGES
+++ b/CHANGES
@@ -1,3 +1,5 @@
+0.1.4
+
 0.1.3
 - completed "post_update" feature, will add a second update statement before inserts
 and after deletes in order to reconcile a relationship without any dependencies
index 7200aa01628a2bdd7a1682b7b48a002358b75239..e31f63034c80c615dd58439f888553c7426c6a38 100644 (file)
@@ -6,8 +6,8 @@ import sys
 # extend from a common base class, although this same approach can be used
 # with 
 
-#db = create_engine('sqlite://', echo=True, echo_uow=False)
-db = create_engine('postgres://user=scott&password=tiger&host=127.0.0.1&database=test', echo=True, echo_uow=False)
+db = create_engine('sqlite://', echo=True, echo_uow=False)
+#db = create_engine('postgres://user=scott&password=tiger&host=127.0.0.1&database=test', echo=True, echo_uow=False)
 
 # a table to store companies
 companies = Table('companies', db, 
index 825d3cd755e3f11a91ecad442a4cef271488b242..554b2d5b427c5a3a16814702650dd85c19241c3f 100644 (file)
@@ -68,8 +68,10 @@ class Mapper(object):
             self._synchronizer = sync.ClauseSynchronizer(self, self, sync.ONETOMANY)
             self._synchronizer.compile(self.table.onclause, inherits.tables, TableFinder(table))
             self.inherits = inherits
+            self.noninherited_table = table
         else:
             self.primarytable = self.table
+            self.noninherited_table = self.table
             self._synchronizer = None
             self.inherits = None
             
index 805a625f32e63f7de30047a8f22b1a596a98341e..fc6762b596ba92968c806807cb0afd66b9752a26 100644 (file)
@@ -172,17 +172,12 @@ class PropertyLoader(MapperProperty):
         # if join conditions were not specified, figure them out based on foreign keys
         if self.secondary is not None:
             if self.secondaryjoin is None:
-                self.secondaryjoin = sql.join(self.target, self.secondary).onclause
+                self.secondaryjoin = sql.join(self.mapper.noninherited_table, self.secondary).onclause
             if self.primaryjoin is None:
-                self.primaryjoin = sql.join(parent.table, self.secondary).onclause
-            tf = mapper.TableFinder(self.secondaryjoin, check_columns=True)
-            tf2 = mapper.TableFinder(self.primaryjoin, check_columns=True)
-            for t in tf2:
-                if t is not self.secondary and t in tf:
-                    raise ArgumentError("Ambiguous join conditions generated between '%s' and '%s' (primaryjoin='%s', secondaryjoin='%s'); please specify explicit primaryjoin and/or secondaryjoin arguments to property '%s'" % (parent.table.id, self.target.id, self.primaryjoin, self.secondaryjoin, self.key))
+                self.primaryjoin = sql.join(parent.noninherited_table, self.secondary).onclause
         else:
             if self.primaryjoin is None:
-                self.primaryjoin = sql.join(parent.table, self.target).onclause
+                self.primaryjoin = sql.join(parent.noninherited_table, self.target).onclause
         # if the foreign key wasnt specified and theres no assocaition table, try to figure
         # out who is dependent on who. we dont need all the foreign keys represented in the join,
         # just one of them.  
index 04949c93546e2c24eabe660ab3e8767ccb4a3e39..89b4b55854285e2df1055cdc982003d60dbb6de4 100644 (file)
@@ -1132,6 +1132,7 @@ class CompoundSelect(SelectBaseMixin, FromClause):
         self.selects = selects
         self.use_labels = kwargs.pop('use_labels', False)
         self.parens = kwargs.pop('parens', False)
+        self.correlate = kwargs.pop('correlate', False)
         self.oid_column = selects[0].oid_column
         for s in self.selects:
             s.group_by(None)
index e499bf6cb41252990abebc482e373ccbebf4f8b1..5273a62ec177a9454c31542293c8a7177cf10400 100644 (file)
@@ -132,8 +132,8 @@ class InheritTest2(testbase.AssertMixin):
                 #'id':[bar.c.bid, foo.c.id]
             })
 
-        Bar.mapper.add_property('foos', relation(Foo.mapper, foo_bar, primaryjoin=bar.c.bid==foo_bar.c.bar_id, secondaryjoin=foo_bar.c.foo_id==foo.c.id, lazy=False))
-        #Bar.mapper.add_property('foos', relation(Foo.mapper, foo_bar, lazy=False))
+        #Bar.mapper.add_property('foos', relation(Foo.mapper, foo_bar, primaryjoin=bar.c.bid==foo_bar.c.bar_id, secondaryjoin=foo_bar.c.foo_id==foo.c.id, lazy=False))
+        Bar.mapper.add_property('foos', relation(Foo.mapper, foo_bar, lazy=False))
 
         b = Bar('barfoo')
         objectstore.commit()
@@ -209,8 +209,8 @@ class InheritTest3(testbase.AssertMixin):
                 return "Bar id %d, data %s" % (self.id, self.data)
                 
         Bar.mapper = mapper(Bar, bar, inherits=Foo.mapper, properties={
-        'foos' :relation(Foo.mapper, bar_foo, primaryjoin=bar.c.id==bar_foo.c.bar_id, lazy=False)
-#        'foos' :relation(Foo.mapper, bar_foo, lazy=True)
+        #'foos' :relation(Foo.mapper, bar_foo, primaryjoin=bar.c.id==bar_foo.c.bar_id, lazy=False)
+        'foos' :relation(Foo.mapper, bar_foo, lazy=True)
         })
 
         b = Bar('bar #1')
@@ -239,8 +239,10 @@ class InheritTest3(testbase.AssertMixin):
                 return "Blub id %d, data %s, bars %s, foos %s" % (self.id, self.data, repr([b for b in self.bars]), repr([f for f in self.foos]))
             
         Blub.mapper = mapper(Blub, blub, inherits=Bar.mapper, properties={
-            'bars':relation(Bar.mapper, blub_bar, primaryjoin=blub.c.id==blub_bar.c.blub_id, lazy=False),
-            'foos':relation(Foo.mapper, blub_foo, primaryjoin=blub.c.id==blub_foo.c.blub_id, lazy=False),
+#            'bars':relation(Bar.mapper, blub_bar, primaryjoin=blub.c.id==blub_bar.c.blub_id, lazy=False),
+#            'foos':relation(Foo.mapper, blub_foo, primaryjoin=blub.c.id==blub_foo.c.blub_id, lazy=False),
+            'bars':relation(Bar.mapper, blub_bar, lazy=False),
+            'foos':relation(Foo.mapper, blub_foo, lazy=False),
         })
 
         useobjects = True