Skip to content

Instantly share code, notes, and snippets.

@kgrz
Created September 8, 2012 02:33
Show Gist options
  • Select an option

  • Save kgrz/3671415 to your computer and use it in GitHub Desktop.

Select an option

Save kgrz/3671415 to your computer and use it in GitHub Desktop.
Mongoid unable to create 1-N referenced docs in embedded documents
class Email
include Mongoid::Document
field :emailid, type: String
embeds_many :account
end
class Account
include Mongoid::Document
field :number, type: Integer
field :openedon, type: DateTime
embedded_in :email #Email has one field of type String. Not defined here.
has_many :shadows
end
class Shadow
include Mongoid::Document
field :shadowdate, type: DateTime
field :balance, type: String
belongs_to :account
end
# This fails with the error:
# NoMethodError: Undefined method 'keys' for DateTime:Class
# Replacing has_many :shadows to embeds_many :shadows seems to do the trick. Mongoid
# not able to reference documents in embedded documents.
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment