]> git.ipfire.org Git - thirdparty/sqlalchemy/sqlalchemy.git/commitdiff
"backwards" one-to-one tests (save fails)
authorMike Bayer <mike_mp@zzzcomputing.com>
Thu, 8 Sep 2005 03:41:06 +0000 (03:41 +0000)
committerMike Bayer <mike_mp@zzzcomputing.com>
Thu, 8 Sep 2005 03:41:06 +0000 (03:41 +0000)
test/mapper.py

index 207cb540576fe96ee2754263dacc05fcc6618d59..0a7246a96cf12ff2b6eb36c97b861253ca4b3634 100644 (file)
@@ -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."""