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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 15, 20262026-05-15T23:27:20+00:00 2026-05-15T23:27:20+00:00

This example makes it seem like both are used ( include d) in order

  • 0

This example makes it seem like both are used (included) in order to make a class a persistent model, but it is not clear when I should use one or the other.

  • 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-15T23:27:20+00:00Added an answer on May 15, 2026 at 11:27 pm

    A MongoMapper::Document is saved to the database as a top-level record. A MongoMapper::EmbeddedDocument is saved within another document. For instance, let’s say I have a blogging application. I have a Post and Comment model. They might look something like this:

    require 'mongo_mapper'
    MongoMapper.database = 'test'
    
    class Post
      include MongoMapper::Document
    
      key :title
      key :body
      key :comments
    
      many :comments
    end
    
    class Comment
      include MongoMapper::EmbeddedDocument
    
      key :author
      key :body
    end
    
    p = Post.new(:title => 'Some post', :body => 'About something')
    p.comments << Comment.new(:author => 'Emily', :body => 'A comment')
    
    p.save
    
    puts Post.all.map(&:inspect)
    

    Will produce a document in your mongo database that looks like this:

    { "_id" : ObjectId("4c4dcf4b712337464e000001"),
      "title" : "Some post",
      "body" : "About something",
      "comments" : [
            {
                    "body" : "A comment",
                    "author" : "Emily",
                    "_id" : ObjectId("4c4dcf4b712337464e000002")
            }
    ] }
    

    In terms of interacting with them through MongoMapper, only a MongoMapper::Document response to methods like find and save. A MongoMapper::EmbeddedDocument can only be accessed through its parent document. The implication of this is that you should only use MongoMapper::EmbeddedDocument for models that are clearly subsidiary to their parent models and will only be used in the context of that parent.

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Ask A Question

Stats

  • Questions 530k
  • Answers 530k
  • Best Answers 0
  • User 1
  • Popular
  • Answers
  • Editorial Team

    How to approach applying for a job at a company ...

    • 7 Answers
  • Editorial Team

    What is a programmer’s life like?

    • 5 Answers
  • Editorial Team

    How to handle personal stress caused by utterly incompetent and ...

    • 5 Answers
  • Editorial Team
    Editorial Team added an answer -[NSString capitalizedString] May 16, 2026 at 11:38 pm
  • Editorial Team
    Editorial Team added an answer I don't know of a way to add an option… May 16, 2026 at 11:38 pm
  • Editorial Team
    Editorial Team added an answer I added z-index property to thumbnail: hover span style to… May 16, 2026 at 11:38 pm

Trending Tags

analytics british company computer developers django employee employer english facebook french google interview javascript language life php programmer programs salary

Top Members

Related Questions

Code snippet to follow. I have a struct (example code has class, tried both,
I'm not sure this is possible, but is there a syntax to be used
Coming from a C++ background, Im used to multiple inheritance. I like the feeling
NOTE: the original question is moot but scan to the bottom for something relevant.
What are the differences between shell languages like Bash ( bash ), Z shell
I have spent several hours with this SQL problem, which I thought would be
I've been looking all over for this question... How do I build a soap
I've been using extension methods a lot recently to help make my code be
First post inhere ever. So better make it a good one. I have a
I'm wondering how one can catch and add a custom handler when empty results

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.