【发布时间】:2013-11-30 04:15:26
【问题描述】:
我不知道发生了什么,但我似乎无法找到工作一小段代码。我使用了没有嵌入文档的 mongomappper,一切都很顺利。使用嵌入式文档,我碰到了砖墙。我正在使用 Rails 控制台按照mongomapper homepage 上的说明进行操作:
这是我的模型:
class Assessment
include Mongomapper::Document
many :sections
end
class Section
include MongoMapper::EmbeddedDocument
key :title, String
validates_presence_of :title
end
当我跑步时:a = Assessment.create(:sections => [ Section.new(:title => 'test') ] )
我会得到以下输出:
=> #<Assessment _id: BSON::ObjectId('4e71efce69a74c0fb6000002'), sections: nil>
我也试过a = Assessment.new(),a.sections << Section.new(:title => "test")
但结果相同。
为什么部分里面什么都没有?
【问题讨论】:
-
什么版本的Mongo?什么版本的 MongoMapper?我认为 MongoMapper 和 Mongo 2.0 还不能很好地结合在一起。见:groups.google.com/group/mongomapper/browse_thread/thread/…
-
我检查了我的版本,我运行的是 mongodb 2.0.0、mongomapper 0.9.2、Rails 3.0.10、Ruby 1.9.2p290。我卸载了 mongo 并安装了 1.8.3 版。我得到同样的错误。
-
我想我只是对数据的显示方式感到困惑。 mm 0.9.1 不会打印
sections: nil但 0.9.2 会打印,即使里面有部分... -
嗯,可能是 0.9.2 的事情,可能与 groups.google.com/group/mongomapper/browse_thread/thread/…
标签: ruby-on-rails-3 mongomapper