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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 27, 20262026-05-27T19:26:00+00:00 2026-05-27T19:26:00+00:00

I have three simple models – Car , Details and Details2 . Car have

  • 0

I have three simple models – Car, Details and Details2.
Car have lot of Details and Details have lot of Details2.

With MySQL and ActiveRecord I will set the associations like:

class Car
  has_many :details
end


class Detail
   belongs_to :car
end

In the view, where I have a list of Car, I have:

<% @cars.each do |car| -%>
  <%=car.details.count%> #uninitialized constant Details
<% end %>

EDIT2:
This is what I have in cars table:

db.cars.find()
{ "_id" : ObjectId("4efe69716f85ce447a000054"), "name" : "bmw", "descr" : "asasgasga as gas gas ", "updated_at" : "Sat Dec 31 2011 02:46:25 GMT+0100 (CET)", "created_at" : "Sat Dec 31 2011 02:46:25 GMT+0100 (CET)" }

and details:

db.details.find()
{ "_id" : ObjectId("4f01106d6f85ce6b850000b8"), "car_id" : ObjectId("4efe69716f85ce447a000054"), "name" : "20120102030325", "descr" : "dsg", "updated_at" : "Mon Jan 02 2012 03:03:25 GMT+0100 (CET)", "created_at" : "Mon Jan 02 2012 03:03:25 GMT+0100 (CET)" }

And in CarsController I have in this action only:

def index
  @cars = Car.all
end

that’s all what I do.

  • 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-27T19:26:01+00:00Added an answer on May 27, 2026 at 7:26 pm

    You can reuse what you know from ActiveRecord. has_many and belongs_to work just fine in Mongoid.

    But you can take advantage of document databases (which MongoDB is) and use some embedding. For embedded_in to work correctly you have to have embeds_one or embeds_many on the other end. See http://mongoid.org/docs/relations/embedded/1-1.html

      class Person
        include Mongoid::Document
        embeds_one :name
      end
    
      class Name
        include Mongoid::Document
        field :vorname, type: String
        field :nachname, type: String
        embedded_in :person
      end
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I have three models that i'd like to perform a simple search across: class
I have a simple three table reference. It looks plain enough. The associations there
I have two simple models in my Django app. Here's what they look like:
I have a three models: class Feed < ActiveRecord::Base has_many :filters, :dependent => :destroy
suppose I have a simple container which have three element: <div> <span>hello world</span> <input
I have a simple JavaScript file that has three jQuery $document.ready functions. All three
I have a simple object that allows you to assign three properties (x,y,z) (lets
I have a very simple Setup project that copies three dlls into the GAC.
so I have a simple example--a fully crossed three treatment three context experiment, where
A very simple question. I have a html page which is divided into three

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.