moiristo / deep_cloneable

This gem gives every ActiveRecord::Base object the possibility to do a deep clone that includes user specified associations.
MIT License
785 stars 89 forks source link

STI associations #78

Closed mrsweaters closed 7 years ago

mrsweaters commented 7 years ago

How would this work with STI associations that are not available on the parent?

class Road
end

class Expressway < Road
end

class Highway < Road
  has_many :bridges
end

@new_highway = @road.deep_clone include: :bridges

This is failing for any non-highway roads.

ActiveRecord::Base::DeepCloneable::AssociationNotFoundException: Expressway#bridges
moiristo commented 7 years ago

Hmm, yeah that's not possible yet. Maybe there should be an option like :skip_missing_associations or something.. I'll try to come up with something tonight, should be easy to implement.

mrsweaters commented 7 years ago

@moiristo Thanks for looking into it!

moiristo commented 7 years ago

I just added support for the skip_missing_associations option in master. Could you check if it suits your needs? If everything is ok, I'll make a new release.

mrsweaters commented 7 years ago

@moiristo Thanks! I'll take a look at this and let you know. I really appreciate it!

mrsweaters commented 7 years ago

This worked great!