Frage

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?

War es hilfreich?

Lösung

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!

Lizenziert unter: CC-BY-SA mit Zuschreibung
Nicht verbunden mit StackOverflow
scroll top