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

The Archive Base Latest Questions

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

I have an issue with mongoid inheritance. I have a Zipcode with inherits from

  • 0

I have an issue with mongoid inheritance. I have a Zipcode with inherits from Location class both mongoid documents. It has the following simple inheritance structure:

class Zipcode < Location

Also I have an object which fills out the Zipcode object using nested_attributes. I have noticed when it tries to create the Zipcode object it instead creates a Location object instead. In my test code everything works fine but in my production code things do not work properly.

After running ruby-debug over my code I have found the following behavior in the file: ~/work/Project/bson/ruby/1.9.1/gems/mongoid-2.2.3/lib/mongoid/document.rb:277

Breakpoint 2 at /Users/pc/work/Project/bson/ruby/1.9.1/gems/mongoid-2.2.3/lib/mongoid/document.rb:277
/Users/pc/work/Project/bson/ruby/1.9.1/gems/mongoid-2.2.3/lib/mongoid/document.rb:277
@_type ||= [descendants + [self]].flatten.uniq.map { |t| t.to_s }
(rdb:48) p descendants
[]
(rdb:48) p Zipcode.ancestors && [Location]
[Location]
(rdb:48) p descendants
[Zipcode]
(rdb:48)

See it’s strange that descendants (which is in BasicObject) gets filled out when Zipcode.ancestors is called. I am using Ruby1.9.2, Mongoid 2.2.3 and Rails3.1.1.

Questions: Is there something special in the mongoid syntax to get inheritance in nested attributes? Is there an issue that needs to be fixed in either mongoid, rails or ruby?

Update:

Just to show that breaking into the test code works the first time:

Breakpoint 1 at /Users/pc/work/Project/bson/ruby/1.9.1/gems/mongoid-2.2.3/lib/mongoid/document.rb:277
/Users/pc/work/Project/bson/ruby/1.9.1/gems/mongoid-2.2.3/lib/mongoid/document.rb:277
@_type ||= [descendants + [self]].flatten.uniq.map { |t| t.to_s }
(rdb:1) p descendants
[Zipcode]
  • 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-26T17:13:08+00:00Added an answer on May 26, 2026 at 5:13 pm

    Found the solution had to change

    config.cache_classes = true 
    

    in config/environments/development.rb. It messes up inheritance in rails sometimes apparently.

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

Sidebar

Related Questions

We have an issue using the PEAR libraries on Windows from PHP . Pear
I have an issue with using AWK to simply remove a field from a
I have big issue with url-rewriting for IIS 7.0. I've written simple module for
Much of my sql code is generated (from POD). Now i have issue where
Seems like everyone have issue accessing local machine or internet etc from emulator. All
Have an issue with the following array... I can't navigate it using $arrayname[0]... it
I have a class that looks like this: class SearchService include Mongoid::Document key :name,
I have issue with url rewrite. I have a site example.com that has a
I have issue with my inner join division below. From my oracle, it keep
I have issue with displaying AlertDialog from Service. I am able to display custom

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.