diff options
| author | Mike Bayer <mike_mp@zzzcomputing.com> | 2006-03-09 00:24:15 +0000 |
|---|---|---|
| committer | Mike Bayer <mike_mp@zzzcomputing.com> | 2006-03-09 00:24:15 +0000 |
| commit | b5060e88ff4604af4c9e51003a078dbb59fce968 (patch) | |
| tree | 539fe14f93a268875e1ea4717c50dbaaf3c66e90 | |
| parent | f057ed6136fe5583d4174a55153544783e76699a (diff) | |
| download | sqlalchemy-b5060e88ff4604af4c9e51003a078dbb59fce968.tar.gz | |
added 'noninherited table' prop to mapper indicating the "lead" table, in the case of
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.
| -rw-r--r-- | CHANGES | 2 | ||||
| -rw-r--r-- | examples/polymorph/polymorph.py | 4 | ||||
| -rw-r--r-- | lib/sqlalchemy/mapping/mapper.py | 2 | ||||
| -rw-r--r-- | lib/sqlalchemy/mapping/properties.py | 11 | ||||
| -rw-r--r-- | lib/sqlalchemy/sql.py | 1 | ||||
| -rw-r--r-- | test/inheritance.py | 14 |
6 files changed, 18 insertions, 16 deletions
@@ -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 diff --git a/examples/polymorph/polymorph.py b/examples/polymorph/polymorph.py index 7200aa016..e31f63034 100644 --- a/examples/polymorph/polymorph.py +++ b/examples/polymorph/polymorph.py @@ -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, diff --git a/lib/sqlalchemy/mapping/mapper.py b/lib/sqlalchemy/mapping/mapper.py index 825d3cd75..554b2d5b4 100644 --- a/lib/sqlalchemy/mapping/mapper.py +++ b/lib/sqlalchemy/mapping/mapper.py @@ -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 diff --git a/lib/sqlalchemy/mapping/properties.py b/lib/sqlalchemy/mapping/properties.py index 805a625f3..fc6762b59 100644 --- a/lib/sqlalchemy/mapping/properties.py +++ b/lib/sqlalchemy/mapping/properties.py @@ -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. diff --git a/lib/sqlalchemy/sql.py b/lib/sqlalchemy/sql.py index 04949c935..89b4b5585 100644 --- a/lib/sqlalchemy/sql.py +++ b/lib/sqlalchemy/sql.py @@ -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) diff --git a/test/inheritance.py b/test/inheritance.py index e499bf6cb..5273a62ec 100644 --- a/test/inheritance.py +++ b/test/inheritance.py @@ -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 |
