【发布时间】:2014-08-08 00:07:39
【问题描述】:
我想知道如何与 mongoid 建立多对多关系。这是模型的可视化表示,小的是连接表:
!http://i.imgur.com/lJxoRSb.jpg
我已经使用 RoR 像这样(作为示例)设置了我的模型:
class Event
include Mongoid::Document
field :name, type: String
field :place, type: String
field :when, type: String
field :price, type: Integer
field :participants, type: Integer
field :short_description, type: String
has_many :users
#has_many :users, :through => :user_events
end
我需要什么将事件模型与用户模型和兴趣模型加入(如果这可能的话)?我知道 mongoid 不是最好的选择,但我坚持使用它。
提前致谢!
【问题讨论】:
-
我认为你正在尝试 has_many :through,它在 mongoid 中没有使用。您在这里没有加入。
标签: mongodb ruby-on-rails-4 mongoid