Skip to content

Instantly share code, notes, and snippets.

@bogn
Created October 4, 2011 13:10
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save bogn/1261606 to your computer and use it in GitHub Desktop.
Save bogn/1261606 to your computer and use it in GitHub Desktop.
class Page
include MongoMapper::Document
end
class ContentPage < Page
many :content_blocks #tried :as => :page as well
end
class ContentBlock
include MongoMapper::EmbeddedDocument
belongs_to :content_page
# tried belongs_to :page
# and belongs_to :page, :polymorphic => true
# embedded_in :page didn't make any difference
key :text, String
end
p = Page.find('4e42a6c0cb0f3d2bdc00021e') # is a Page
c = Page.find('4e42da66cb0f3d51f6000045') # is a ContentPage
c.content_blocks
# behaves as expected in mmconsole: [#<ContentBlock _id: BSON::ObjectId('4e8afbe0cb0f3d7846000012'), text: "foo">]
# but not in rails dev console/app: []
# or production console/app: [{"_id"=>BSON::ObjectId('4e78f6efcb0f3d56e80000a6'), "text"=>"foo"}]
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment