开发者

Simple Mongoid associations

I'm just starting with Mongodb using Mongoid in Rails and I'm wondering how to create the simple associations between these three models:

User which has many Photos which has many Tags which has many Photos

I don't want to embed any of th开发者_JAVA技巧e models since I want to be able to present a list of for instance all Photos or all Tags in certain views…

Thanks!


Check out the Mongoid Docs on Associations. Look under "RELATIONAL ASSOCIATIONS"

class User
  include Mongoid::Document 
  references_many :photos
end

class Photos
  include Mongoid::Document
  referenced_in :user
end
0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜