-
Notifications
You must be signed in to change notification settings - Fork 89
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Missing relations in new (cloned) model #70
Comments
What kind of association are we talking about? Did it clone the categories? Are the products still missing after saving the copy? |
I've come across this issue as well, and it seems to be due to the use of a multi-item hash inside the record.deep_clone(include: { relation1: :attr1, relation2: :attr2 }) record.deep_clone(include: [:relation3, { relation1: :attr1 }, { relation2: :attr2 }]) but does not support using a single hash inside the array if it has multiple keys: record.deep_clone(include: [:relation3, { relation1: :attr1, relation2: :attr2 }]) record.deep_clone(include: [:relation3, relation1: :attr1, relation2: :attr2]) I agree this is a tad confusing/unexpected since the last format would be the more idiomatic way to write this in Rails these days. I toyed around for a bit with the code but couldn't find a way to make this work without breaking some of the other use cases, but here's a test to show the problem: def test_multiple_and_deep_include_association_with_array
deep_clone = @jack.deep_clone(include: [:parrot, treasures: :gold_pieces, mateys: {}])
assert deep_clone.new_record?
assert deep_clone.save
assert_equal 1, deep_clone.treasures.size
assert_equal 1, deep_clone.gold_pieces.size
assert_equal 1, deep_clone.mateys.size
end For now, the second format I showed above (with explicitly separate hashes) can be used if you want to mix array and hash relations. PS: Thank you for this wonderful gem. It's helped me greatly optimize a tedious workflow in one of my projects. :) |
Thanks! I'll check it out soon, should be fixable I think.. |
I fixed the test now in 517537d by 'normalizing' the includes list (converting multikey hashes to singular hashes). Should be ok I think? |
Im cloning an event object with nested models like show here:
The result is a cloned object, but misses the
categories: :products
on the copy. The use ofuse_dictionary
doesn't seem to make a difference. I tried various alternatives, but never ended up with the required result. Can you give me some advice here?The text was updated successfully, but these errors were encountered: