]> git.ipfire.org Git - thirdparty/sqlalchemy/sqlalchemy.git/commitdiff
unit tests for dangling subquery, many-to-many clear-and-resave
authorMike Bayer <mike_mp@zzzcomputing.com>
Wed, 14 Jun 2006 15:39:46 +0000 (15:39 +0000)
committerMike Bayer <mike_mp@zzzcomputing.com>
Wed, 14 Jun 2006 15:39:46 +0000 (15:39 +0000)
test/orm/objectstore.py
test/sql/select.py

index 83d279a284197d0cc9f2abb5f7da44bb6b07cf84..4dc9624a98dc2e884ac7817835601f6736ada722 100644 (file)
@@ -1027,6 +1027,42 @@ class SaveTest(SessionTest):
         
         ctx.current.delete(objects[3])
         ctx.current.flush()
+
+
+    def testmanytomanyupdate(self):
+        class Keyword(object):
+            def __init__(self, name):
+                self.name = name
+            def __eq__(self, other):
+                return other.name == self.name
+            def __repr__(self):
+                return "Keyword(%s, %s)" % (getattr(self, 'keyword_id', 'None'), self.name)
+                
+        mapper(Keyword, keywords)
+        mapper(Item, orderitems, properties = dict(
+                keywords = relation(Keyword, secondary=itemkeywords, lazy=False),
+            ))
+
+        (k1, k2, k3) = (Keyword('keyword 1'), Keyword('keyword 2'), Keyword('keyword 3'))
+        item = Item()
+        item.item_name = 'item 1'
+        item.keywords.append(k1)
+        item.keywords.append(k2)
+        item.keywords.append(k3)
+        ctx.current.flush()
+        
+        item.keywords = []
+        item.keywords.append(k1)
+        item.keywords.append(k2)
+        print item.keywords.unchanged_items()
+        print item.keywords.added_items()
+        print item.keywords.deleted_items()
+        ctx.current.flush()
+        
+        ctx.current.clear()
+        item = ctx.current.query(Item).get(item.item_id)
+        print [k1, k2]
+        assert item.keywords == [k1, k2]
         
     def testassociation(self):
         class IKAssociation(object):
index 2481e04aed8e98e71c89eead27ddc7a9cd2ab75f..290e324cf2cd75013348b05ac2d88c4bb3630269 100644 (file)
@@ -124,6 +124,11 @@ sq.mytable_description AS sq_mytable_description, sq.myothertable_otherid AS sq_
 sq.myothertable_othername AS sq_myothertable_othername FROM (" + sqstring + ") AS sq) AS sq2")
 
     def testwheresubquery(self):
+        # TODO: this tests that you dont get a "SELECT column" without a FROM but its not working yet.
+        #self.runtest(
+        #    table1.select(table1.c.myid == select([table1.c.myid], table1.c.name=='jack')), ""
+        #)
+        
         self.runtest(
             table1.select(table1.c.myid == select([table2.c.otherid], table1.c.name == table2.c.othername)),
             "SELECT mytable.myid, mytable.name, mytable.description FROM mytable WHERE mytable.myid = (SELECT myothertable.otherid AS otherid FROM myothertable WHERE mytable.name = myothertable.othername)"