新手问题 Mongoid 中的 key 是什么意思?

u1355214846 · February 19, 2013 · Last by u1355214846 replied at February 20, 2013 · 2330 hits

class Author
  include Mongoid::Document
  field :name
  key :name
  references_many :articles
end

上面的 key:name 中的 key 代表什么意思?哪位老师了解?谢谢!

用来自定义主键的;默认主键是 id (_id)。我印象中 key 一般用于将几个 fields 组合起来做主键。

额,我在 Mongoid Doc 中没找到 key , 还有 references_many 也没在 Mongoid Relation 中找到... 是不是用了老版本的 API ?

#2 楼 @wppurking 那段代码是 mongoid2.0 的,我也没有在 doc 中找到

You need to Sign in before reply, if you don't have an account, please Sign up first.