【发布时间】:2012-07-28 00:48:04
【问题描述】:
我有一个包含一个项目的数据模型,其中包含一个建议列表,每个建议都是由用户创建的。有没有一种方法可以创建在项目中提出建议的所有不同用户的列表?
我正在使用 Mongoid 3。我在想这样的事情,但它不起作用:
@project = Project.find(params[:id])
@users = Array.new
@users.push(@project.suggestions.user) <-- this doesn't work
有什么想法吗?这是我的模型结构:
class Project
include Mongoid::Document
has_many :suggestions, :dependent => :destroy
...
end
class Suggestion
include Mongoid::Document
belongs_to :author, class_name: "User", :inverse_of => :suggestions
belongs_to :project
...
end
class User
include Mongoid::Document
has_many :suggestions, :inverse_of => :author
...
end
【问题讨论】:
-
我用我的模型更新了问题,并指出我正在使用 Mongoid 3。