English 中文(简体)
关于MongoMapper,文件与一份受文件区别如何?
原标题:On MongoMapper, what is the difference between a Document and an EmbeddedDocument?

这一实例似乎都使用过(included),以使某一类别成为一种持久性模式,但不清楚何时我应使用一种或另一种模式。

最佳回答

www.un.org/chinese/ga/president http://www.ohchr.org。 例如,我要说的是,我有博客申请。 缩略语 他们可以这样看待:

require  mongo_mapper 
MongoMapper.database =  test 

class Post
  include MongoMapper::Document

  key :title
  key :body
  key :comments

  many :comments
end

class Comment
  include MongoMapper::EmbeddedDocument

  key :author
  key :body
end

p = Post.new(:title =>  Some post , :body =>  About something )
p.comments << Comment.new(:author =>  Emily , :body =>  A comment )

p.save

puts Post.all.map(&:inspect)

将在贵族数据库中编制一份文件,其中研究:

{ "_id" : ObjectId("4c4dcf4b712337464e000001"),
  "title" : "Some post",
  "body" : "About something",
  "comments" : [
        {
                "body" : "A comment",
                "author" : "Emily",
                "_id" : ObjectId("4c4dcf4b712337464e000002")
        }
] }

就通过MongoMapper与他们互动而言,只有MongoMapper:Documentfindsave等方法的答复。 缩略语 只能通过上级文件查阅。 其含义是,你只应使用<代码>MongoMapper:EmbeddedDocument,用于明显与其母体模型相配套的模型,而且只能用于母体。

问题回答

暂无回答




相关问题
Ruby parser in Java

The project I m doing is written in Java and parsers source code files. (Java src up to now). Now I d like to enable parsing Ruby code as well. Therefore I am looking for a parser in Java that parses ...

rails collection_select vs. select

collection_select and select Rails helpers: Which one should I use? I can t see a difference in both ways. Both helpers take a collection and generates options tags inside a select tag. Is there a ...

RubyCAS-Client question: Rails

I ve installed RubyCAS-Client version 2.1.0 as a plugin within a rails app. It s working, but I d like to remove the ?ticket= in the url. Is this possible?

Ordering a hash to xml: Rails

I m building an xml document from a hash. The xml attributes need to be in order. How can this be accomplished? hash.to_xml

multiple ruby extension modules under one directory

Can sources for discrete ruby extension modules live in the same directory, controlled by the same extconf.rb script? Background: I ve a project with two extension modules, foo.so and bar.so which ...

Text Editor for Ruby-on-Rails

guys which text editor is good for Rubyonrails? i m using Windows and i was using E-Texteditor but its not free n its expired now can anyone plese tell me any free texteditor? n which one is best an ...

热门标签