class Activity < ActiveRecord::Base
has_one :sport
belongs_to :place
class Sport < ActiveRecord::Base
has_many :activities, :class_name => "Activity", :foreign_key => "sport_id"
has_many :places, through: :activities
class Place < ActiveRecord::Base
has_many :activities, :class_name => "Activity", :foreign_key => "place_id"
has_many :sports, through: :activities
def show
@places = Place.where(:activities.sport_id => @sport.id).sort{ |a,b| b.activityfrequency(@sport.name) <=> a.activityfrequency(@sport.name)}.take(10)
end
答案 0 :(得分:4)
您必须使用如下所示的活动记录的加入功能。
Place.joins(:活动,:体育).order(:频率).limit(10)