0
喜有3种型号:关键字,网站,导致Rails 3的模型联接限制到一个结果
class Keyword < ActiveRecord::Base
has_many :results
has_many :sites, through: :results
end
class Site < ActiveRecord::Base
has_many :results
has_many :keywords, through: :results
end
class Result < ActiveRecord::Base
belongs_to :site
belongs_to :keyword
end
在sites_controller我想显示所有关键字的列表,该关键字的最新结果一起和现场。
这个连接给我关键字的所有结果,我怎么能限制它只是每个关键字的最新结果?
@keywords = Keyword.joins(:results).where("results.site_id = ?", @site.id).includes(:results).order('keywords.created_at ASC').load
我试图限制结果为1个而不是关键字或关键词秩序 – Drewsdesign