lib/embedded_associations.rb in embedded_associations-4.0.0 vs lib/embedded_associations.rb in embedded_associations-4.1.0
- old
+ new
@@ -85,12 +85,17 @@
unless definition.is_a? Hash
definition = {definition => nil}
end
definition.each do |name, child_definition|
+ if !parent_params || !parent_params.has_key?(name.to_s)
+ next
+ end
+
reflection = parent.class.reflect_on_association(name)
- attrs = parent_params && parent_params.delete(name.to_s)
+
+ attrs = parent_params.delete(name.to_s)
if reflection.collection?
attrs ||= []
handle_plural_resource parent, name, attrs, child_definition
else
@@ -129,20 +134,20 @@
def handle_singular_resource(parent, name, attrs, child_definition)
current_assoc = parent.send(name)
if r = current_assoc
- if attrs
+ if attrs && attrs != ''
attrs = controller.send(:filter_attributes, r.class.name, attrs, :update)
handle_resource(child_definition, r, attrs) if child_definition
r.assign_attributes(attrs)
run_before_update_callbacks(r)
else
handle_resource(child_definition, r, attrs) if child_definition
run_before_destroy_callbacks(r)
r.mark_for_destruction
end
- elsif attrs
+ elsif attrs && attrs != ''
r = parent.send("build_#{name}")
attrs = controller.send(:filter_attributes, r.class.name, attrs, :create)
handle_resource(child_definition, r, attrs) if child_definition
r.assign_attributes(attrs)
run_before_create_callbacks(r)