-
Notifications
You must be signed in to change notification settings - Fork 21.6k
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Fix bug with autosave collection association on new record with a marked for destroy record in autosave collection. Fixes #6918.
- Loading branch information
Francesco Rodriguez
committed
Jul 2, 2012
1 parent
9e0b3fc
commit b1e509a
Showing
2 changed files
with
31 additions
and
15 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Original file line | Diff line number | Diff line change |
---|---|---|---|
|
@@ -332,25 +332,31 @@ def save_collection_association(reflection) | ||
|
|
||
if records = associated_records_to_validate_or_save(association, @new_record_before_save, autosave) | if records = associated_records_to_validate_or_save(association, @new_record_before_save, autosave) | ||
begin | begin | ||
records.each do |record| | records_to_destroy = [] | ||
next if record.destroyed? |
|
||
records.each do |record| | |||
next if record.destroyed? | |||
This comment has been minimized.
Sorry, something went wrong.
This comment has been minimized.
Sorry, something went wrong. |
|||
|
|||
saved = true | |||
|
|||
if autosave && record.marked_for_destruction? | |||
records_to_destroy << record | |||
elsif autosave != false && (@new_record_before_save || record.new_record?) | |||
This comment has been minimized.
Sorry, something went wrong.
fingermark
|
|||
if autosave | |||
saved = association.insert_record(record, false) | |||
else | |||
association.insert_record(record) unless reflection.nested? | |||
end | |||
elsif autosave | |||
saved = record.save(:validate => false) | |||
end | |||
|
|
||
saved = true | raise ActiveRecord::Rollback unless saved | ||
end | |||
|
|
||
if autosave && record.marked_for_destruction? | records_to_destroy.each do |record| | ||
association.proxy.destroy(record) | association.proxy.destroy(record) | ||
elsif autosave != false && (@new_record_before_save || record.new_record?) | |||
if autosave | |||
saved = association.insert_record(record, false) | |||
else | |||
association.insert_record(record) unless reflection.nested? | |||
end | |||
elsif autosave | |||
saved = record.save(:validate => false) | |||
end | end | ||
|
|||
raise ActiveRecord::Rollback unless saved | |||
end | |||
rescue | rescue | ||
records.each {|x| IdentityMap.remove(x) } if IdentityMap.enabled? | records.each {|x| IdentityMap.remove(x) } if IdentityMap.enabled? | ||
raise | raise | ||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
It'd be nice if the collection to be operated on had its logic outside of the operations, so we don't have to follow logic like this "next" method. It seems like there are lots of different things going on here in general, also record skipping and setting a "saved" variable and then potentially acting on that variable state.
edit: this method is too large. Is it too late to refactor?