summaryrefslogtreecommitdiff
path: root/test/orm/inheritance5.py
diff options
context:
space:
mode:
authorMike Bayer <mike_mp@zzzcomputing.com>2007-05-17 22:33:52 +0000
committerMike Bayer <mike_mp@zzzcomputing.com>2007-05-17 22:33:52 +0000
commitc5530d15b3ccc6de9230fbee443d5cda1d38b774 (patch)
treeffaf9c99d21a36a4cb46013da4b83c348b43791c /test/orm/inheritance5.py
parent779068fb41a216f65f6cd18d50b261e378ed67ac (diff)
downloadsqlalchemy-c5530d15b3ccc6de9230fbee443d5cda1d38b774.tar.gz
- the "primary_key" argument to mapper() is propigated to the "polymorphic"
mapper. primary key columns in this list get normalized to that of the mapper's local table.
Diffstat (limited to 'test/orm/inheritance5.py')
-rw-r--r--test/orm/inheritance5.py48
1 files changed, 48 insertions, 0 deletions
diff --git a/test/orm/inheritance5.py b/test/orm/inheritance5.py
index 43f1fa3ca..1c4214635 100644
--- a/test/orm/inheritance5.py
+++ b/test/orm/inheritance5.py
@@ -835,6 +835,54 @@ class ManyToManyPolyTest(testbase.ORMTest):
mapper(Collection, collection_table)
class_mapper(BaseItem)
+
+class CustomPKTest(testbase.ORMTest):
+ def define_tables(self, metadata):
+ global t1, t2
+ t1 = Table('t1', metadata,
+ Column('id', Integer, primary_key=True),
+ Column('type', String(30), nullable=False),
+ Column('data', String(30)))
+ t2 = Table('t2', metadata,
+ Column('t2id', Integer, ForeignKey('t1.id'), primary_key=True),
+ Column('t2data', String(30)))
+ def test_custompk(self):
+ """test that the primary_key attribute is propigated to the polymorphic mapper"""
+
+ class T1(object):pass
+ class T2(T1):pass
+
+ # create a polymorphic union with the select against the base table first.
+ # with the join being second, the alias of the union will
+ # pick up two "primary key" columns. technically the alias should have a
+ # 2-col pk in any case but the leading select has a NULL for the "t2id" column
+ d = util.OrderedDict()
+ d['t1'] = t1.select(t1.c.type=='t1')
+ d['t2'] = t1.join(t2)
+ pjoin = polymorphic_union(d, None, 'pjoin')
+
+ #print pjoin.original.primary_key
+ #print pjoin.primary_key
+ assert len(pjoin.primary_key) == 2
+
+ mapper(T1, t1, polymorphic_on=t1.c.type, polymorphic_identity='t1', select_table=pjoin, primary_key=[pjoin.c.id])
+ mapper(T2, t2, inherits=T1, polymorphic_identity='t2')
+ print [str(c) for c in class_mapper(T1).primary_key]
+ ot1 = T1()
+ ot2 = T2()
+ sess = create_session()
+ sess.save(ot1)
+ sess.save(ot2)
+ sess.flush()
+ sess.clear()
+
+ # query using get(), using only one value. this requires the select_table mapper
+ # has the same single-col primary key.
+ assert sess.query(T1).get(ot1.id).id is ot1.id
+
+ ot1 = sess.query(T1).get(ot1.id)
+ ot1.data = 'hi'
+ sess.flush()
if __name__ == "__main__":
testbase.main()