diff options
| author | Mike Bayer <mike_mp@zzzcomputing.com> | 2012-09-28 11:00:53 -0400 |
|---|---|---|
| committer | Mike Bayer <mike_mp@zzzcomputing.com> | 2012-09-28 11:00:53 -0400 |
| commit | 4aba2eb6017de5d4b56d4aa34af87f2ebab903b0 (patch) | |
| tree | 8bc1ebfe192df559e4ec507818d88156eabb903e /test | |
| parent | 21cac5b598a83ef0e24423dc523629b475aa3af0 (diff) | |
| download | sqlalchemy-4aba2eb6017de5d4b56d4aa34af87f2ebab903b0.tar.gz | |
- fix annotation transfer when producing m2m backref, [ticket:2578]
Diffstat (limited to 'test')
| -rw-r--r-- | test/orm/test_rel_fn.py | 54 | ||||
| -rw-r--r-- | test/orm/test_relationships.py | 29 |
2 files changed, 75 insertions, 8 deletions
diff --git a/test/orm/test_rel_fn.py b/test/orm/test_rel_fn.py index f5fa1d4c9..dfe0db488 100644 --- a/test/orm/test_rel_fn.py +++ b/test/orm/test_rel_fn.py @@ -135,6 +135,22 @@ class _JoinFixtures(object): **kw ) + def _join_fixture_m2m_backref(self, **kw): + """return JoinCondition in the same way RelationshipProperty + calls it for a backref on an m2m. + + """ + j1 = self._join_fixture_m2m() + return j1, relationships.JoinCondition( + self.m2mright, + self.m2mleft, + self.m2mright, + self.m2mleft, + secondary=self.m2msecondary, + primaryjoin=j1.secondaryjoin_minus_local, + secondaryjoin=j1.primaryjoin_minus_local + ) + def _join_fixture_o2m(self, **kw): return relationships.JoinCondition( self.left, @@ -688,16 +704,42 @@ class ColumnCollectionsTest(_JoinFixtures, fixtures.TestBase, AssertsCompiledSQL ) def test_determine_local_remote_pairs_m2m_backref(self): - joincond = self._join_fixture_m2m() - joincond2 = self._join_fixture_m2m( - primaryjoin=joincond.secondaryjoin, - secondaryjoin=joincond.primaryjoin - ) + j1, j2 = self._join_fixture_m2m_backref() eq_( - joincond.local_remote_pairs, + j1.local_remote_pairs, [(self.m2mleft.c.id, self.m2msecondary.c.lid), (self.m2mright.c.id, self.m2msecondary.c.rid)] ) + eq_( + j2.local_remote_pairs, + [ + (self.m2mright.c.id, self.m2msecondary.c.rid), + (self.m2mleft.c.id, self.m2msecondary.c.lid), + ] + ) + + def test_determine_local_columns_m2m_backref(self): + j1, j2 = self._join_fixture_m2m_backref() + eq_( + j1.local_columns, + set([self.m2mleft.c.id]) + ) + eq_( + j2.local_columns, + set([self.m2mright.c.id]) + ) + + def test_determine_remote_columns_m2m_backref(self): + j1, j2 = self._join_fixture_m2m_backref() + eq_( + j1.remote_columns, + set([self.m2msecondary.c.lid, self.m2msecondary.c.rid]) + ) + eq_( + j2.remote_columns, + set([self.m2msecondary.c.lid, self.m2msecondary.c.rid]) + ) + def test_determine_remote_columns_m2o_selfref(self): joincond = self._join_fixture_m2o_selfref() diff --git a/test/orm/test_relationships.py b/test/orm/test_relationships.py index 394a1fe7a..c1cbc0907 100644 --- a/test/orm/test_relationships.py +++ b/test/orm/test_relationships.py @@ -2706,9 +2706,9 @@ class InvalidRelationshipEscalationTestM2M(_RelationshipErrors, fixtures.MappedT mapper(Foo, foos, properties={ 'bars': relationship(Bar, secondary=foobars_with_many_columns, - primaryjoin=foos.c.id== + primaryjoin=foos.c.id == foobars_with_many_columns.c.fid, - secondaryjoin=foobars_with_many_columns.c.bid== + secondaryjoin=foobars_with_many_columns.c.bid == bars.c.id)}) mapper(Bar, bars) sa.orm.configure_mappers() @@ -2721,6 +2721,31 @@ class InvalidRelationshipEscalationTestM2M(_RelationshipErrors, fixtures.MappedT [(bars.c.id, foobars_with_many_columns.c.bid)] ) + def test_local_col_setup(self): + foobars_with_fks, bars, Bar, Foo, foos = ( + self.tables.foobars_with_fks, + self.tables.bars, + self.classes.Bar, + self.classes.Foo, + self.tables.foos) + + # ensure m2m backref is set up with correct annotations + # [ticket:2578] + mapper(Foo, foos, properties={ + 'bars': relationship(Bar, secondary=foobars_with_fks, backref="foos") + }) + mapper(Bar, bars) + sa.orm.configure_mappers() + eq_( + Foo.bars.property._join_condition.local_columns, + set([foos.c.id]) + ) + eq_( + Bar.foos.property._join_condition.local_columns, + set([bars.c.id]) + ) + + def test_bad_primaryjoin(self): foobars_with_fks, bars, Bar, foobars, Foo, foos = (self.tables.foobars_with_fks, |
