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

Conditional include only works for the first record of a has_many association #74

Closed facingsouth closed 7 years ago

facingsouth commented 7 years ago

Here's my code, I want to skip any document without files on it

  def dup_info
    {
      users: [
        { profile: [:model1, :model2] },
        { documents: [ if: lambda{|doc| doc.file.present?} ] }
      ]
    }
  end

 kopy = original.deep_clone(include: dup_info)

only the first user of kopy is skipping the docs without a file on it, all other users still have all the documents on them. Am I doing anything wrong here?

I had tried put if: lambda{|doc| doc.file.present?} into an array or a hash, got the same result.

moiristo commented 7 years ago

Hi,

The code looks ok. The condition is evaluated here. As it seems to do the same for all objects in the association, it doesn't look like the issue is in deep_cloneable. If you think otherwise, could you provide a failing testcase?