提交 634c9310 编写于 作者: J José Valim

Make the logic for nested_records_changed_for_autosave? simpler.

[#4648 state:resolved]
上级 7eedc3f3
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 @@ def associated_records_to_validate_or_save(association, new_record, autosave)
# 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
......
Markdown is supported
0% .
You are about to add 0 people to the discussion. Proceed with caution.
先完成此消息的编辑!
想要评论请 注册