Association Scope
class Review < ActiveRecord::Base
belongs_to :restaurant
scope :positive, -> { where("rating > 3.0") }
end
class Restaurant < ActiveRecord::Base
has_many :reviews
has_many :postitive_reviews, -> { positive }, class_name: "Review"
endrestaurants = Restaurant.includes(:positive_reviews).first(5)最后更新于