]> git.ipfire.org Git - thirdparty/sqlalchemy/sqlalchemy.git/commitdiff
- added add() and add_all() methods to Session, rel_0_4_7
authorMike Bayer <mike_mp@zzzcomputing.com>
Sat, 26 Jul 2008 16:30:59 +0000 (16:30 +0000)
committerMike Bayer <mike_mp@zzzcomputing.com>
Sat, 26 Jul 2008 16:30:59 +0000 (16:30 +0000)
establishing forwards compatibility with 0.5.

CHANGES
lib/sqlalchemy/orm/session.py
test/orm/session.py

diff --git a/CHANGES b/CHANGES
index be67d3aed6a06a04f73692cce0f31b13401f2ee3..c6a9e0bd2b65f0dc31414d97df7e3dfb22e78e9c 100644 (file)
--- a/CHANGES
+++ b/CHANGES
@@ -14,6 +14,9 @@ CHANGES
       "modified" history to be properly cleared after
       a flush() (backported from 0.5).
 
+    - added add() and add_all() methods to Session,
+      establishing forwards compatibility with 0.5.
+      
     - fixed bug preventing merge() from functioning in 
       conjunction with a comparable_property()
 
index 641f87df4b9d866756dbdf296771d3bce6daebd8..9efe52d847f34bddbbed84f9768d6aa6e83a9cd2 100644 (file)
@@ -930,6 +930,23 @@ class Session(object):
         self._save_or_update_impl(instance, entity_name=entity_name)
         self._cascade_save_or_update(instance)
 
+    def add(self, instance, entity_name=None):
+        """Add the given instance into this ``Session``.
+
+        This provides forwards compatibility with 0.5.
+
+        """
+        self.save_or_update(instance, entity_name)
+
+    def add_all(self, instances):
+        """Add the given collection of instances to this ``Session``.
+        
+        This provides forwards compatibility with 0.5.
+        """
+
+        for instance in instances:
+            self.add(instance)
+
     def _cascade_save_or_update(self, instance):
         for obj, mapper in _cascade_iterator('save-update', instance, halt_on=lambda c:c in self):
             self._save_or_update_impl(obj, mapper.entity_name)
index ca9aae835d17398b08fcea04297ea5d35fd005c6..d9c11745f43c265808a90de5f06b35228263e012 100644 (file)
@@ -147,7 +147,23 @@ class SessionTest(TestBase, AssertsExecutionResults):
         session.flush(objects=set())
         session.flush(objects=())
         session.flush(objects=iter([]))
-
+    
+    def test_forwards_compat_add(self):
+        class User(object):pass
+        mapper(User, users)
+        sess = create_session()
+        u1 = User()
+        sess.add(u1)
+        assert u1 in sess
+        u2, u3 = User(), User()
+        sess.add_all([u2, u3])
+        assert u2, u3 in sess
+        sess.flush()
+        sess.expunge(u1)
+        assert u1 not in sess
+        sess.add(u1)
+        assert u1 in sess
+        
     @testing.unsupported('sqlite', 'mssql') # TEMP: test causes mssql to hang
     @engines.close_open_connections
     def test_autoflush(self):