Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 6181233
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 24, 20262026-05-24T00:59:01+00:00 2026-05-24T00:59:01+00:00

I am using Mongoid and I have 2 models, Flow and Node with a

  • 0

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?

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-05-24T00:59:03+00:00Added an answer on May 24, 2026 at 12:59 am

    You should be able to use flow.nodes.clear as long as you don’t have :dependent => :destroy set. From the Rails Guide on Association Basics:

    4.3.1.7 collection.clear

    The collection.clear method removes every object from the collection.
    This destroys the associated objects if they are associated with
    :dependent => :destroy, deletes them directly from the database if
    :dependent => :delete_all, and otherwise sets their foreign keys to
    NULL
    .

    If this isn’t working for you, you could try this and it should remove the association:

    flow.nodes = nil
    

    EDIT 1

    If not, you’ll have to create a method to remove the association manually.

       flow.nodes.update_all :flow_id => nil
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I'm using Mongoid, Devise and Rails 3.1. I have four models: Students, Teacher, Parents
Using Mongoid, let's say I have the following classes: class Map include Mongoid::Document embeds_many
I have the following models in my app and I am using mongoid User,
class Contest < ActiveRecord::Base has_one :claim_template end class ClaimTemplate include Mongoid::Document belongs_to :contest end
I have a Recipe model, which has Ingredients embedded in it, using Mongoid. class
I am using Mongoid and have a project and a user model. in the
I have recently been getting my feet wet in MongoDB using Mongoid w/ Rails
I have been using MongoDB and the Ruby driver and Mongoid, and lines db.things.find({j:
I have two entities, projects and users. These are modeled in Rails using Mongoid
I have a model like this: class Search include Mongoid::Document embeds_many :terms accepts_nested_attributes_for :terms

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.