diff options
author | Mike Bayer <mike_mp@zzzcomputing.com> | 2009-08-08 22:21:02 +0000 |
---|---|---|
committer | Mike Bayer <mike_mp@zzzcomputing.com> | 2009-08-08 22:21:02 +0000 |
commit | a04da2a417726055da205bd604a1993eb4fd9887 (patch) | |
tree | 1b106d1a624599cdfdd62abcacbee8948b22da3c /test/orm/inheritance/test_basic.py | |
parent | cbdccb7fd26da432ddf43ae1820656505acad37e (diff) | |
download | sqlalchemy-a04da2a417726055da205bd604a1993eb4fd9887.tar.gz |
- added **kw to ClauseElement.compare(), so that we can smarten up the "use_get" operation
- many-to-one relation to a joined-table subclass now uses get()
for a simple load (known as the "use_get" condition),
i.e. Related->Sub(Base), without the need
to redefine the primaryjoin condition in terms of the base
table. [ticket:1186]
- specifying a foreign key with a declarative column,
i.e. ForeignKey(MyRelatedClass.id) doesn't break the "use_get"
condition from taking place [ticket:1492]
Diffstat (limited to 'test/orm/inheritance/test_basic.py')
-rw-r--r-- | test/orm/inheritance/test_basic.py | 52 |
1 files changed, 52 insertions, 0 deletions
diff --git a/test/orm/inheritance/test_basic.py b/test/orm/inheritance/test_basic.py index b2e00de35..778b08a27 100644 --- a/test/orm/inheritance/test_basic.py +++ b/test/orm/inheritance/test_basic.py @@ -208,6 +208,58 @@ class CascadeTest(_base.MappedTest): assert t4_1 in sess.deleted sess.flush() +class M2OUseGetTest(_base.MappedTest): + @classmethod + def define_tables(cls, metadata): + Table('base', metadata, + Column('id', Integer, primary_key=True, test_needs_autoincrement=True), + Column('type', String(30)) + ) + Table('sub', metadata, + Column('id', Integer, ForeignKey('base.id'), primary_key=True), + ) + Table('related', metadata, + Column('id', Integer, primary_key=True, test_needs_autoincrement=True), + Column('sub_id', Integer, ForeignKey('sub.id')), + ) + + @testing.resolve_artifact_names + def test_use_get(self): + # test [ticket:1186] + class Base(_base.BasicEntity): + pass + class Sub(Base): + pass + class Related(Base): + pass + mapper(Base, base, polymorphic_on=base.c.type, polymorphic_identity='b') + mapper(Sub, sub, inherits=Base, polymorphic_identity='s') + mapper(Related, related, properties={ + # previously, this was needed for the comparison to occur: + # the 'primaryjoin' looks just like "Sub"'s "get" clause (based on the Base id), + # and foreign_keys since that join condition doesn't actually have any fks in it + #'sub':relation(Sub, primaryjoin=base.c.id==related.c.sub_id, foreign_keys=related.c.sub_id) + + # now we can use this: + 'sub':relation(Sub) + }) + + assert class_mapper(Related).get_property('sub').strategy.use_get + + sess = create_session() + s1 = Sub() + r1 = Related(sub=s1) + sess.add(r1) + sess.flush() + sess.expunge_all() + + r1 = sess.query(Related).first() + s1 = sess.query(Sub).first() + def go(): + assert r1.sub + self.assert_sql_count(testing.db, go, 0) + + class GetTest(_base.MappedTest): @classmethod def define_tables(cls, metadata): |