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
精彩评论