summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorMike Bayer <mike_mp@zzzcomputing.com>2013-11-30 16:17:27 -0500
committerMike Bayer <mike_mp@zzzcomputing.com>2013-11-30 16:17:27 -0500
commit12b05adbb118b8501eb79abeb2c821e1a8f89ce9 (patch)
tree2a868a0e1a7c112a3b9b7f5e651bda10d778419b
parent92d8baeb95204ddc2c6b78a1c63194b04e3ae952 (diff)
parent8fc91105a0ee484fb9c76e7e957c78a5f1901ddb (diff)
downloadsqlalchemy-12b05adbb118b8501eb79abeb2c821e1a8f89ce9.tar.gz
Merge branch 'orm-collections-list-clear' of github.com:schettino72/sqlalchemy into list_clear
-rw-r--r--lib/sqlalchemy/orm/collections.py8
-rw-r--r--test/orm/test_collection.py10
2 files changed, 18 insertions, 0 deletions
diff --git a/lib/sqlalchemy/orm/collections.py b/lib/sqlalchemy/orm/collections.py
index 6bd5ac968..ffd0b8c37 100644
--- a/lib/sqlalchemy/orm/collections.py
+++ b/lib/sqlalchemy/orm/collections.py
@@ -1161,6 +1161,14 @@ def _list_decorators():
_tidy(pop)
return pop
+ def clear(fn):
+ def clear(self, index=-1):
+ for item in self:
+ __del(self, item)
+ fn(self)
+ _tidy(clear)
+ return clear
+
# __imul__ : not wrapping this. all members of the collection are already
# present, so no need to fire appends... wrapping it with an explicit
# decorator is still possible, so events on *= can be had if they're
diff --git a/test/orm/test_collection.py b/test/orm/test_collection.py
index f6493f1a8..f94c742b3 100644
--- a/test/orm/test_collection.py
+++ b/test/orm/test_collection.py
@@ -284,6 +284,16 @@ class CollectionsTest(fixtures.ORMTest):
del control[:]
assert_eq()
+ if hasattr(direct, 'clear'):
+ for i in range(1, 4):
+ e = creator()
+ direct.append(e)
+ control.append(e)
+
+ direct.clear()
+ control.clear()
+ assert_eq()
+
if hasattr(direct, 'extend'):
values = [creator(), creator(), creator()]