class Entry < ActiveRecord::Base
belongs_to :user
belongs_to :job
end
class User < ActiveRecord::Base
has_many :entries
has_many :jobs, through: :entries
end
class Job < ActiveRecord::Base
belongs_to :job_type
has_many :entries
has_many :users, through: :entries
end
我一直在尝试一段时间,似乎无法得到此。我想通过条目选择分配给用户的所有作业(user_id:1)。任何帮助都会很棒。Rails has_many通过ActiveRecord查询
注:我试过
Job.find(3).entries
但只是返回有3
完美,伟大的工程!非常感谢(还有Steve和Jack) – user3007294