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

  • Home
  • SEARCH
  • 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 6571733
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 25, 20262026-05-25T14:55:10+00:00 2026-05-25T14:55:10+00:00

I have two Document Models that are proving problematic: class Component include Mongoid::Document include

  • 0

I have two Document Models that are proving problematic:

class Component
  include Mongoid::Document
  include Mongoid::Versioning

  recursively_embeds_many
end

class Institution
  include Mongoid::Document

  has_many :components
end

I understand that you shouldn’t be able to reference an embedded model from another document. I’m hoping however that with the recursively embedded documents there’s a way to reference the top of the tree from another document? If this is not possible to use these relationships together at all, what alternatives do I have to setup a one-to-many relationship between Institution and Component while maintaining the recursive nature of component?

  • 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-25T14:55:10+00:00Added an answer on May 25, 2026 at 2:55 pm

    What you are trying to do sounds reasonable but Mongoid won’t let you associate a class that can be embedded with another class via an association. When I gave it a try I got an exception raised in this file (line 218) when adding a (top-level) Component to an Institution.

    The simplest option for you would be to embed Component in Institution, e.g.

    class Institution
      include Mongoid::Document
    
      embeds_many :components
    end
    

    Otherwise, if you want to share Component trees with different Institutions I guess you would need to introduce some kind of container object into the model and define a many-many association to Institution, e.g.:

    class Component
      include Mongoid::Document
      include Mongoid::Versioning
    
      recursively_embeds_many
    end
    
    class ComponentTree
      include Mongoid::Document
    
      embeds_many :components
      has_and_belongs_to_many :institutions
    end
    
    class Institution
      include Mongoid::Document
    
      has_and_belongs_to_many :component_trees
    end
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I have been given two different Microsoft Word document that my virus scanner has
I have a Delphi 7 application that has two views of a document (e.g.
I have two tables that have already been created. Document and DocumentStyle . They
We have two Tables: Document: id, title, document_type_id, showon_id DocumentType: id, name Relationship: DocumentType
I have two applications written in Java that communicate with each other using XML
I have two types of text that need to follow similar coloring rules based
Lets say we have a simple model that stores two integers, the min and
I have two functions function ShowCrossWord(var randN) { randomnumber = randN; $(document).ready(function() { $.get(crosswords.xml,{},function(xml){
We have two subdomains for the same site, we would like that depending on
I have two g:select comboboxes that I want to add to the multiple select

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.