开发者

Simple Mongoid associations

开发者 https://www.devze.com 2023-02-06 17:57 出处:网络
I\'m just starting with Mongodb using Mongoid in Rails and I\'m wondering how to create the simple associations between these three models:

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

精彩评论

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