我有以下AR关系,
class Restaurant < ActiveRecord::Base
has_many :deals
end
class Deal < ActiveRecord::Base
belongs_to :restaurant
acts_as_taggable_on :tags
end
我想要做的是找到与给定标签的交易,并返回相关的restaurants
。
我的Restaurant
型号
scope :food_type, ->(food_types){
select("*")
joins(:deals).merge(Deal.tagged_with([food_types], any: true, wild: true ))
}
但问题是,当我致电Restaurant.food_type(<tags>)
时,它会返回与Restaurant
个Deal
数据对象的ActiveRecord关系
例如:#<Restaurant id: 383, name: "sample deal name", note: "sample deal note", created_at: "2014-03-18 22:36:27", updated_at: "2014-03-18 22:36:27"
我甚至在范围内使用select
,没有任何运气。如何从上述范围返回Restaurant
属性?