From: Mike Bayer Date: Thu, 8 Sep 2005 03:41:06 +0000 (+0000) Subject: "backwards" one-to-one tests (save fails) X-Git-Tag: rel_0_1_0~765 X-Git-Url: http://git.ipfire.org/cgi-bin/gitweb.cgi?a=commitdiff_plain;h=7cbaee905bd6c469221b8e511254b396a523ac14;p=thirdparty%2Fsqlalchemy%2Fsqlalchemy.git "backwards" one-to-one tests (save fails) --- 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."""