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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 26, 20262026-05-26T10:08:58+00:00 2026-05-26T10:08:58+00:00

Ok, so firstly Im not very in the know when it comes to Ruby,

  • 0

Ok, so firstly Im not very in the know when it comes to Ruby, Rails, Mongo or even ActiveRecord so I apologise if these questions are fairly basic. Firstly, I have an “Event” model and I have added a many relationship to my “Comment” model. Now it is my (basic) understanding of mongo (or any document db) that foreign key lookups (or whatever they are called in mongo) are not advised, instead opting for storing as much as possible in a single document. With this in mind I would expect to have a single Events collection with the Comment JSON/BSON embedded in each document i.e.

event:

{
 Title: "some event"
 Comments : [
    { user_id: [object id], comment: "comment"}, 
    { user_id: [object id], comment: "other comment"}
 ]
}

Instead I am seeing that a comments collection has been created as well as the event collection. Would this be the correct way to map this relationship, if so how do I stop the comment collection been created and instead have the info embedded directly into the event? My guess is that I have to tell my Comment mapping not to have a _id property and thus not belong to its own collection.


EDIT: I found out that what I was looking for here in my first question was to use MongoMapper::EmbeddedDocument instead of including MongoMapper::Document


Secondly, I want users to be able to flag themselves as “attending” or just “interested” an event, which I assumed would be modelled as an array of reference user_id’s on the event. So I initially thought it would be mapped as two “many” relationships, but as far as I can tell the name of the constant I am passing to the many method is used to create the getter/setters, which wouldn’t work for me if I had two many relationships for the same type.

In other words, if I have this mapping:

class Event
   many :users
end

Then it’s my understanding that I will then have getters and setters generated for the users property. So I can do something like:

event.users << someAttendingUser

This is all good, and at this point in time I would want the reference to the user to be stored and not the whole user BSON (unlike with the comments example above). Now the problem is how do I do this when I have two many mappings to the user collection, as with my need for both “attending” and “interested” users?

So to summarise this rambling:

  • Sometimes I want to store many relationships directly as BSON in the orinal document, and not as a reference to a document in another collection. How do I do this?

  • Sometimes I want to store many relationships of the same type on a document and I DO want them to be references to a document in another collection. How do I do this?

Hope this made sense, and I apologise if Im asking the obvious here.


EDIT 2:

Ok, well I really did search before asking this question, but it appears that I have now found the answer to both of my problems so I will close the question myself.

The second part required me to specify a class name option for the mapping i.e.

class Event
   many :attendees, :class_name  => "User"
   many :interested, :class_name  => "User"
end

  • 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-26T10:08:59+00:00Added an answer on May 26, 2026 at 10:08 am

    Ok, well I really did search before asking this question, but it appears that I have now found the answer to both of my problems so I will close the question myself.

    The second part required me to specify a class name option for the mapping i.e.

    class Event
       many :attendees, :class_name  => "User"
       many :interested, :class_name  => "User"
    end
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

Firstly, sorry about the question title, it may not be very descriptive for my
Firstly, I feel sorry about the title, I do not know how to describe
I'm not very experienced in this area - so I've got a few questions.
Ok, firstly this is not about forms this is about consistent layout as a
Firstly, I do not have any malicious intent out of this question. I would
Firstly, I want to apologize for my English, not my strongest side. To the
I am not able to understand few things on the Garbage collection. Firstly, how
Firstly this is not a homework question. I am practicing my knowledge on java.
Firstly, I am not at all familiar with Windows batch file programing. Recently I
Firstly, I'm not against Opera. It just seems when I encounter cross browser issues,

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.