aboutsummaryrefslogtreecommitdiffstats
path: root/activerecord/lib/active_record
diff options
context:
space:
mode:
authorJosé Valim <jose.valim@gmail.com>2010-06-07 11:00:39 +0200
committerJosé Valim <jose.valim@gmail.com>2010-06-07 11:01:10 +0200
commit634c9310e302aba0c113363ccec748460113b523 (patch)
tree50a7de54451adc1be81709912df471f1d2bf6385 /activerecord/lib/active_record
parent7eedc3f3975cca2b7e729fcb67e310977b5e5dcd (diff)
downloadrails-634c9310e302aba0c113363ccec748460113b523.tar.gz
rails-634c9310e302aba0c113363ccec748460113b523.tar.bz2
rails-634c9310e302aba0c113363ccec748460113b523.zip
Make the logic for nested_records_changed_for_autosave? simpler.
[#4648 state:resolved]
Diffstat (limited to 'activerecord/lib/active_record')
-rw-r--r--activerecord/lib/active_record/autosave_association.rb14
1 files changed, 5 insertions, 9 deletions
diff --git a/activerecord/lib/active_record/autosave_association.rb b/activerecord/lib/active_record/autosave_association.rb
index 59a7bc1da1..0dcadfab5f 100644
--- a/activerecord/lib/active_record/autosave_association.rb
+++ b/activerecord/lib/active_record/autosave_association.rb
@@ -1,3 +1,5 @@
+require 'active_support/core_ext/array/wrap'
+
module ActiveRecord
# AutosaveAssociation is a module that takes care of automatically saving
# your associations when the parent is saved. In addition to saving, it
@@ -238,16 +240,10 @@ module ActiveRecord
# go through nested autosave associations that are loaded in memory (without loading
# any new ones), and return true if is changed for autosave
def nested_records_changed_for_autosave?
- self.class.reflect_on_all_autosave_associations.each do |reflection|
- if association = association_instance_get(reflection.name)
- if [:belongs_to, :has_one].include?(reflection.macro)
- return true if association.target && association.target.changed_for_autosave?
- else
- return true if association.target.detect { |record| record.changed_for_autosave? }
- end
- end
+ self.class.reflect_on_all_autosave_associations.any? do |reflection|
+ association = association_instance_get(reflection.name)
+ association && Array.wrap(association.target).any?(&:changed_for_autosave?)
end
- false
end
# Validate the association if <tt>:validate</tt> or <tt>:autosave</tt> is