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.
+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
# 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,
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
# 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.
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)
#'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()
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')
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