aboutsummaryrefslogtreecommitdiffstats
path: root/activerecord/lib/active_record
diff options
context:
space:
mode:
authorDavid Heinemeier Hansson <david@loudthinking.com>2004-12-15 15:09:44 +0000
committerDavid Heinemeier Hansson <david@loudthinking.com>2004-12-15 15:09:44 +0000
commit7500a5469231665e5d65f47ff75e55097f096e09 (patch)
treefa437e7d31433ce5753694d6f134365bbb14092e /activerecord/lib/active_record
parent120649dc8302122e32fb2e57fe36246f4ecf878e (diff)
downloadrails-7500a5469231665e5d65f47ff75e55097f096e09.tar.gz
rails-7500a5469231665e5d65f47ff75e55097f096e09.tar.bz2
rails-7500a5469231665e5d65f47ff75e55097f096e09.zip
Added automatic transaction block around AssociationCollection.<<, AssociationCollection.delete, and AssociationCollection.destroy_all
git-svn-id: http://svn-commit.rubyonrails.org/rails/trunk@171 5ecf4fe2-1ee6-0310-87b1-e25e094e27de
Diffstat (limited to 'activerecord/lib/active_record')
-rw-r--r--activerecord/lib/active_record/associations/association_collection.rb25
1 files changed, 17 insertions, 8 deletions
diff --git a/activerecord/lib/active_record/associations/association_collection.rb b/activerecord/lib/active_record/associations/association_collection.rb
index 00758aa66c..5c7770e739 100644
--- a/activerecord/lib/active_record/associations/association_collection.rb
+++ b/activerecord/lib/active_record/associations/association_collection.rb
@@ -37,11 +37,14 @@ module ActiveRecord
# Add +records+ to this association. Returns +self+ so method calls may be chained.
# Since << flattens its argument list and inserts each record, +push+ and +concat+ behave identically.
def <<(*records)
- flatten_deeper(records).each do |record|
- raise_on_type_mismatch(record)
- insert_record(record)
- @collection << record if loaded?
+ @owner.transaction do
+ flatten_deeper(records).each do |record|
+ raise_on_type_mismatch(record)
+ insert_record(record)
+ @collection << record if loaded?
+ end
end
+
self
end
@@ -51,13 +54,19 @@ module ActiveRecord
# Remove +records+ from this association. Does not destroy +records+.
def delete(*records)
records = flatten_deeper(records)
- records.each { |record| raise_on_type_mismatch(record) }
- delete_records(records)
- records.each { |record| @collection.delete(record) } if loaded?
+
+ @owner.transaction do
+ records.each { |record| raise_on_type_mismatch(record) }
+ delete_records(records)
+ records.each { |record| @collection.delete(record) } if loaded?
+ end
end
def destroy_all
- each { |record| record.destroy }
+ @owner.transaction do
+ each { |record| record.destroy }
+ end
+
@collection = []
end