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

Add scope option to dup relationships #66

Closed DiogoAlves92 closed 5 years ago

DiogoAlves92 commented 8 years ago

Add a scope option to dup relationships.

This could be usefull, for example, to ensure that objects are created given a certain order (for example, by their ids).

Given the treasure model:

scope :ordered, -> { order(id: :desc) }

Usage:

pirate.deep_clone include: { treasures: {}, scope: :ordered }

What do you think?

moiristo commented 8 years ago

Hi, thanks for your PR! I'm not sure if it is really useful though. AR already gives you the possibility to scope associations by specifying a second argument, I thought it was something like:

class Pirate < ActiveRecord::Base
  has_many :treasures, ->{ order(id: :desc) }
end

Is there a case in which it would be useful to specify a different order scope than the one provided in the association? If there is, it's fine with me to merge this in. We should add some tests for it first in that case.