Mike Bayer avatar Mike Bayer committed feb03a8

- added add() and add_all() methods to Session,
establishing forwards compatibility with 0.5.

Comments (0)

Files changed (3)

       "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()
 

lib/sqlalchemy/orm/session.py

         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)

test/orm/session.py

         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):
Tip: Filter by directory path e.g. /media app.js to search for public/media/app.js.
Tip: Use camelCasing e.g. ProjME to search for ProjectModifiedEvent.java.
Tip: Filter by extension type e.g. /repo .js to search for all .js files in the /repo directory.
Tip: Separate your search with spaces e.g. /ssh pom.xml to search for src/ssh/pom.xml.
Tip: Use ↑ and ↓ arrow keys to navigate and return to view the file.
Tip: You can also navigate files with Ctrl+j (next) and Ctrl+k (previous) and view the file with Ctrl+o.
Tip: You can also navigate files with Alt+j (next) and Alt+k (previous) and view the file with Alt+o.