Closed johnnaegle closed 9 years ago
Thanks! However, I think that a more straightforward way should also be supported, agreed? For example:
@ship.deep_clone(:include => [:pirates => [:treasures, :mateys, :unless => lambda {|pirate| pirate.name == 'Jack Sparrow'}]])
I think I can easily add this if you like..
Yes, that would be cleaner
On Thu, Apr 2, 2015 at 3:13 AM, Reinier de Lange notifications@github.com wrote:
Thanks! However, I think that a more straightforward way should also be supported, agreed? For example:
@ship.deep_clone(:include => [:pirates => [:treasures, :mateys, :unless => lambda {|pirate| pirate.name == 'Jack Sparrow'}]])
I think I can easily add this if you like..
— Reply to this email directly or view it on GitHub https://github.com/moiristo/deep_cloneable/pull/48#issuecomment-88816517 .
Added in master.
It took me a long time to figure out the syntax for cloning associations with conditionals, so I wrote a test. Previously, I was using the array syntax for associations, but adding conditions required to switching to a hash syntax and I could not figure out what the right hand side of the hash. An empty array worked and I wrote a test for it.
Previously, I was cloning like this:
But then I needed conditionals on the pirates so the pirates associations array becomes a hash like this:
and then the conditional can be added.
This test really just documents how you add conditionals to array based cloning.