GithubHelp home page GithubHelp logo

Comments (4)

moiristo avatar moiristo commented on July 29, 2024

What kind of association are we talking about? Did it clone the categories? Are the products still missing after saving the copy?

from deep_cloneable.

joshleitzel avatar joshleitzel commented on July 29, 2024

I've come across this issue as well, and it seems to be due to the use of a multi-item hash inside the include array. The deep_clone method appears to accept these formats:

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. :)

from deep_cloneable.

moiristo avatar moiristo commented on July 29, 2024

Thanks! I'll check it out soon, should be fixable I think..

from deep_cloneable.

moiristo avatar moiristo commented on July 29, 2024

I fixed the test now in 517537d by 'normalizing' the includes list (converting multikey hashes to singular hashes). Should be ok I think?

from deep_cloneable.

Related Issues (20)

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.