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?

有帮助吗?

解决方案

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!

许可以下: CC-BY-SA归因
不隶属于 StackOverflow
scroll top