Closed gangleton closed 8 years ago
You're follow_up
association looks a bit mangled, what's going on there?
follow_up
is has_many
, therefore it should be follow_ups
, or it should be a has_one
association insteadQuestion
? Then why is its foreign key id called parent_option_id
?What actually happens (I think) is the following:
Option
record is found and clonedfollow_up
association is found and clonedFollowUp
, deep_cloneable passes the cloned option to the inverse association (should be something like belongs_to :option, inverse_of: :follow_up
in follow_up)Option
object. That's what the error shows. Therefore I think your associations are not correctly specified.follow_up
is a naming problem that I inherited with this code base, I know it's not correct.
A follow_up
is a question that belongs to an option. Options have two associations with Questions- one as a belongs_to
, and one as has_many
. The other side of that is
Question belongs_to :option, :foreign_key => "parent_option_id", inverse_of: :follow_up
The foreign key is stored on Question.
Ok, I need to reproduce the error in the test suite first in order to fix it. I'll try to add one shortly.. unless you'd like to give it a try yourself of course ;)
I should be able to do that this afternoon…
On Sep 13, 2016, at 12:12 PM, Reinier de Lange notifications@github.com wrote:
Ok, I need to reproduce the error in the test suite first in order to fix it. I'll try to add one shortly.. unless you'd like to give it a try yourself of course ;)
— You are receiving this because you authored the thread. Reply to this email directly, view it on GitHub https://github.com/moiristo/deep_cloneable/issues/67#issuecomment-246791604, or mute the thread https://github.com/notifications/unsubscribe-auth/AAM3e8imrYqFU82P5OAtKj4mMI4oeEXbks5qpvWdgaJpZM4J7DFl.
This should be fixed by #71 (release 2.2.2).
I'm trying to deep clone an object with several associations:
When I try to deep clone a poll object,
poll.deep_clone include: { questions: [ {options: :follow_up} ] }
, I get the errorNoMethodError: undefined method 'each' for #<Option:0x007fd87d419490>
,with the following trace:
It seems to be an issue when the association doesn't use the same name as the class of the object, similar to https://github.com/moiristo/deep_cloneable/issues/58
Any idea how to get around this?