ActiveRecord与select Rails 4连接

时间:2014-03-20 08:12:15

标签: ruby-on-rails activerecord

我有以下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>)时,它会返回与RestaurantDeal数据对象的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属性?

0 个答案:

没有答案