Created
September 8, 2012 02:33
-
-
Save kgrz/3671415 to your computer and use it in GitHub Desktop.
Mongoid unable to create 1-N referenced docs in embedded documents
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| 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