Permalink
Browse files

let the object stay in charge of internal cache invalidation

  • Loading branch information...
1 parent 9abcb13 commit 634fd040dbabf3e268a6a4bf4a9136468222022f @tenderlove tenderlove committed Jun 13, 2013
@@ -306,14 +306,9 @@ def accepts_nested_attributes_for(*attr_names)
attr_names.each do |association_name|
if reflection = reflect_on_association(association_name)
- reflection.options[:autosave] = true
+ reflection.autosave = true
add_autosave_association_callbacks(reflection)
- # Clear cached values of any inverse associations found in the
- # reflection and prevent the reflection from finding inverses
- # automatically in the future.
- reflection.remove_automatic_inverse_of!
-
nested_attributes_options = self.nested_attributes_options.dup
nested_attributes_options[association_name.to_sym] = options
self.nested_attributes_options = nested_attributes_options
@@ -123,6 +123,11 @@ def initialize(macro, name, scope, options, active_record)
name.to_s.pluralize : name.to_s
end
+ def autosave=(autosave)
+ @automatic_inverse_of = false
+ @options[:autosave] = autosave
+ end
+
# Returns the class for the macro.
#
# <tt>composed_of :balance, class_name: 'Money'</tt> returns the Money class
@@ -312,13 +317,6 @@ def clear_inverse_of_cache!
@inverse_of = nil
end
- # Removes the cached inverse association that was found automatically
- # and prevents this object from finding the inverse association
- # automatically in the future.
- def remove_automatic_inverse_of!
- @automatic_inverse_of = false
- end
-
def polymorphic_inverse_of(associated_class)
if has_inverse?
if inverse_relationship = associated_class.reflect_on_association(options[:inverse_of])

0 comments on commit 634fd04

Please sign in to comment.