moiristo/deep_cloneable — Issue #11: Rails 3.0.9 not picking up has_many association
Author: pvencill
Created: 2011-11-22 06:03:19+00:00
State: open

I am trying to follow your example. I have a set of objects arranged something like folders of forms.

So, each folder belongs to a user, and has_many forms, each form has_many answers.

When I try and clone using deep_cloneable, I don't get the parents set right. So for example:

new_folder = folder.clone :include=>[:user, {:forms => :answers}]

It populates the in-memory objects with all the cloned values correctly, *except* I get validation errors that the form's folder_id is nil but is required, and the answers' form_id is nil and is required. I recognize that I could remove those validation checks if I wanted, but it seems like an odd thing to fail on, given that I have :autosave=>true on the has_many relationships.

Conversely the user_id is likewise required ,but it does *not* throw a validation error, and that belongs_to attribute does not have autosave turned on.

Any ideas how to resolve this?