Embedded documents show up as nil in Documents #373

burningTyger opened this Issue Dec 31, 2011 · 5 comments

5 participants


Seems like this has been brought up before as an issue but I can't find any solution. Two simple classes like this:

class Address
  include MongoMapper::EmbeddedDocument

  key :address, String

class Person
  include MongoMapper::Document

  many :addresses

person = Person.new
person.addresses << Address.new(:address => 'Home sweet home')

will end up as:

 => #<Person _id: BSON::ObjectId('4efeca5602c94c8139000001'), addresses: nil> 

However, in my db it is there. But whatever I do I can't access addresses.

I have a current gem and mongodb installed (0.10.1 and 2.0.2) on Mac OS X Lion


I have also been observing this for a while now. When you run person.inspect in Rails it will show addresses as nil, like in your example, however when you run person.addresses.inspect it will show the address, so it is not nil at all.


ok, thank you @jnunemaker, this seems to solve the issue. If nobody has to add anything to this I'll close it tomorrow.

@kkamil kkamil added a commit to kkamil/mongomapper that referenced this issue Feb 12, 2012
@kkamil kkamil fix issue #373 74a76e5
@bryckbost bryckbost added a commit to collectiveidea/mongomapper that referenced this issue Feb 25, 2012
@bryckbost bryckbost Merge branch 'nunesmaster'
* nunesmaster: (40 commits)
  Allow MongoMapper.setup to accept a symbol for the environment name so Sinatra's settings.environment value can be used.
  another fix in inspect
  fix issue #373
  Fix and test for displaying embedded documents
  Release 0.11.0
  Added timestamps! to EmbeddedDocument
  Document change to update_attribute
  Fix accessible/protected tests after change to update_attribute
  ActiveSupport::Concern's automatic inclusion of the InstanceMethods module is deprecated
  Fix add_to_set/push_uniq test typos
  Fuzzy match development dependency requirements on the minor version
  rename `connection_options` to `options` and create a test
  use mongodb connection options from yaml config file
  rename test
  move reflect_on_association to Rails module
  Make update_attribute behave like in ActiveRecord
  ActiveRecord compatible association reflection
  added :context option to validates_associated
  Added namespacing to model generator
  Add OneEmbeddedPolymorphicProxy (the last missing polymorphic proxy)

For MongoMapper 0.11.2 this is no longer an issue over here (was with 0.11). kkamil's changes fixed it, just mentioning it to potentially raise some issue-closing attention. The issues list got a little large.

@cheald cheald closed this Jul 8, 2013
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment