From 7cbaee905bd6c469221b8e511254b396a523ac14 Mon Sep 17 00:00:00 2001 From: Mike Bayer Date: Thu, 8 Sep 2005 03:41:06 +0000 Subject: [PATCH] "backwards" one-to-one tests (save fails) --- test/mapper.py | 30 ++++++++++++++++++++++++++++++ 1 file changed, 30 insertions(+) diff --git a/test/mapper.py b/test/mapper.py index 207cb54057..0a7246a96c 100644 --- a/test/mapper.py +++ b/test/mapper.py @@ -132,6 +132,14 @@ class LazyTest(AssertMixin): print repr(l) print repr(l[0].address) + # test 'backwards' + m = mapper(Address, addresses, properties = dict( + user = relation(User, users, primaryjoin = users.c.user_id == addresses.c.user_id, lazy = True, uselist = False) + )) + l = m.select(addresses.c.address_id == 1) + print repr(l) + print repr(l[0].user) + def testmanytomany(self): """tests a many-to-many lazy load""" items = orderitems @@ -180,6 +188,14 @@ class EagerTest(AssertMixin): print repr(l) print repr(l[0].address) + # test 'backwards' + m = mapper(Address, addresses, properties = dict( + user = relation(User, users, primaryjoin = addresses.c.user_id == users.c.user_id, lazy = False, uselist = False) + )) + l = m.select(addresses.c.address_id == 1) + print repr(l) + print repr(l[0].user) + def testwithrepeat(self): """tests a one-to-many eager load where we also query on joined criterion, where the joined criterion is using the same tables that are used within the eager load. the mapper must insure that the @@ -352,6 +368,20 @@ class SaveTest(AssertMixin): u.address.email_address = 'imnew@foo.com' m.save(u) m.save(u) + + def testbackwardsonetoone(self): + # test 'backwards' + m = mapper(Address, addresses, properties = dict( + user = relation(User, users, primaryjoin = users.c.user_id == addresses.c.user_id, lazy = True, uselist = False) + )) + a = Address() + a.email_address = 'themaster@foo.com' + a.user = User() + a.user.user_name = 'thesub' + m.save(a) + l = sql.select([users, addresses], sql.and_(users.c.user_id==addresses.c.address_id, addresses.c.address_id==a.address_id)).execute() + r = engine.ResultProxy(l) + print repr(r.fetchone().row) def testonetomany(self): """test basic save of one to many.""" -- 2.47.2