Permalink
Browse files

Add an :autosave association option, defaulting to true for "many" an…

…d embedded "one" associations to remain consistent with current behavior.
  • Loading branch information...
laserlemon committed Mar 7, 2011
1 parent e6bd6d3 commit 7cf80d8729d8eb5bfc43e4fb1f63469f70a9c2ca
@@ -83,7 +83,7 @@ def save_to_collection(options={})
super if defined?(super)
associations.each do |association_name, association|
proxy = get_proxy(association)
proxy.save_to_collection(options) if proxy.proxy_respond_to?(:save_to_collection) && association.options[:autosave]
proxy.save_to_collection(options) if proxy.proxy_respond_to?(:save_to_collection) && association.autosave?
end
end
end
@@ -62,6 +62,10 @@ def proxy_class
def setup(model)
end
def autosave?
raise NotImplementedError
end
private
def separate_options_and_conditions
@original_options.each_pair do |key, value|
@@ -48,6 +48,10 @@ def create_#{name}!(attrs={})
end
end_eval
end
def autosave?
options.fetch(:autosave, false)
end
end
end
end
@@ -58,6 +58,9 @@ def #{name}=(value)
end
end
def autosave?
options.fetch(:autosave, true)
end
end
end
end
@@ -10,6 +10,10 @@ def embeddable?
def proxy_class
@proxy_class ||= klass.embeddable? ? OneEmbeddedProxy : OneProxy
end
def autosave?
options.fetch(:autosave, embeddable?)
end
end
end
end

0 comments on commit 7cf80d8

Please sign in to comment.