我有一个包含一个项目的数据模型,其中包含一个建议列表,每个建议都是由用户创建的。有没有办法可以创建在项目中提出建议的所有不同用户的列表?
我正在使用 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