I am using Mongoid and I have 2 models, Flow and Node with a referenced parent-child relationship.
class Node
belongs_to :flow
end
class Flow
has_many :nodes
end
When I want to remove a node with a flow I do this:
flow.nodes.clear
This destroy the associated nodes. What if I want to remove the association between the node and the flow without destroying the associated nodes? Is there a way of doing that?
You should be able to use
flow.nodes.clearas long as you don’t have:dependent => :destroyset. From the Rails Guide on Association Basics:If this isn’t working for you, you could try this and it should remove the association:
EDIT 1
If not, you’ll have to create a method to remove the association manually.