提案のリストを含むプロジェクトを含むデータモデルがあり、各提案はユーザーによって作成されます。プロジェクト内で提案を行ったすべての個別のユーザーのリストを作成する方法はありますか?
私はMongoid3を使用しています。私はこのようなことを考えていましたが、機能しません。
@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