lib/embedded_associations.rb in embedded_associations-4.1.0 vs lib/embedded_associations.rb in embedded_associations-4.1.1
- old
+ new
@@ -121,11 +121,17 @@
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
- r = current_assoc.build()
+ inheritance_column = parent.class.reflect_on_association(name).klass.inheritance_column
+ # need to pass in inheritance column in build to get correct class
+ r = if inheritance_column
+ current_assoc.build(attrs.slice(inheritance_column))
+ else
+ current_assoc.build()
+ end
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)
end
@@ -145,10 +151,16 @@
handle_resource(child_definition, r, attrs) if child_definition
run_before_destroy_callbacks(r)
r.mark_for_destruction
end
elsif attrs && attrs != ''
- r = parent.send("build_#{name}")
+ inheritance_column = parent.class.reflect_on_association(name).klass.inheritance_column
+ # need to pass in inheritance column in build to get correct class
+ r = if inheritance_column
+ parent.send("build_#{name}", attrs.slice(inheritance_column))
+ else
+ parent.send("build_#{name}")
+ end
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)
end