lib/ninja_model/associations.rb in ninja-model-0.6.0 vs lib/ninja_model/associations.rb in ninja-model-0.6.1
- old
+ new
@@ -75,11 +75,19 @@
association.target = target
association_instance_set(reflection.name, association)
end
end
- def collection_accessor_methods(reflection, association_proxy_class)
+ def collection_accessor_methods(reflection, association_proxy_class, writer = true)
collection_reader_method(reflection, association_proxy_class)
+
+ if writer
+ redefine_method("#{reflection.name}=") do |new_value|
+ association = send(reflection.name)
+ association.replace(new_value)
+ association
+ end
+ end
end
def collection_reader_method(reflection, association_proxy_class)
redefine_method(reflection.name) do |*params|
association = association_instance_get(reflection.name)