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 8261505
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 8, 20262026-06-08T03:25:57+00:00 2026-06-08T03:25:57+00:00

I recently posted this question: How to model a many self-referential relationship with many

  • 0

I recently posted this question: How to model a many self-referential relationship with many parents?

I got an adequate answer, but I was told that I could model this better using Mongo/Mongoid. I always wanted to attempt using a different database paradigm so maybe this will be a good start.

Is it true that this would be easier to model using Mongo? If so, could you help lay it out for me?

I basically have two options right? 1 is to create an array through a document that references Skill id’s through it? E.g, Skill.prerequisites = [Skill1, Skill2, Skill3]. Something that works with that structure right?

Otherwise it may be that I need to run something logical on that association so I’d have to create a separate model. This is where I get confused. Given I may need to create a separate model, does that exist as a document or an embedded document? What are my limitations w/ each strategy?

  • 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-06-08T03:25:58+00:00Added an answer on June 8, 2026 at 3:25 am

    OK, so let’s go with your skill approach. Here’s how I’d model it in Mongoid:

    class Skill
      include Mongoid::Document
    
      field :prereqruisite_skill_ids, type: Array, default: []
    
      def prereqruisite_skills
        Skill.any_of(:_id => prereqruisite_skill_ids).all
      end
    
      def add_prereqruisite!(skill)
        self.prereqruisite_skill_ids << skill
        safely.save!
      end
    end
    

    With Mongo, this is the only way I would do it.

    With ActiveRecord, you could:

    class Skill < AR::Base
      has_many :skill_prereqruisites
      has_many :prerequisites, through: skill_prereqruisites, class_name: "Skill"
    end
    
    class SkillPrereqruisite < AR::Base
      belongs_to :skill_one, foreign_key: "skill_one_id"
      belongs_to :skill_two, foreign_key: "skill_two_id"
    end
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I recently posted this question on the r-help mailing list but got no answers,
Hello I recently posted this question but very badly explained the problem, but i'll
I recently posted this question which worked locally with the answer I selected as
As demonstrated in this answer I recently posted, I seem to be confused about
Recently I posted a question about the html helper dropdownlist and got it working
This question is related to another one I've posted recently: Check printing with Java/JSP
I've recently posted a question in this forum asking for any advice regarding missing
I recently came across this interview question (posted in a forum somehwere... looks like
Apologies if this question is already posted. I didn't find the answer i was
I posted a question recently: Initialization of Static Class members. Now please check this

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.