1

I am using deep_cloneable gem. I can do deep copying of the association, and also I can exclude the attributes from the parent object. But is there a way to exclude the attributes even from the associations?

chetu
  • 245
  • 3
  • 15

1 Answers1

3

It looks like you can explicitly exclude attributes from the parent or the association or both. Here's an example directly from the docs:

pirate.dup :include => :parrot, :except => [:name, { :parrot => [:name] }]

For your case, you'll want to leave off the :name of the parent like this:

pirate.dup :include => :parrot, :except => [{ :parrot => [:name] }]

As an aside, you can also include attributes from just the association, which could serve your needs just fine if you want to use a whitelisting technique. This is the example directly from the docs:

pirate.dup :include => :parrot, :only => [:name, { :parrot => [:name] }]

What you probably want to do for whitelisting is this:

pirate.dup :include => :parrot, :only => [{ :parrot => [:name] }]

Hope this helps!

WattsInABox
  • 4,548
  • 2
  • 33
  • 43