(对象不支持#inspect)rails 4.2.7(5.0也是如此)

时间:2017-03-30 11:20:16

标签: mysql ruby-on-rails ruby-on-rails-4 activerecord ruby-on-rails-5

以下查询正常。

SELECT coupon_campaigns.id as coupon_campaign_id FROM commerce.monthly_coupon_counters INNER JOIN coupons ON coupons.id = monthly_coupon_counters.coupon_id INNER JOIN coupon_campaigns ON coupon_campaigns.id = coupons.coupon_campaign_id WHERE coupon_campaigns.id IN (11, 12, 13) GROUP BY coupon_campaigns.id

但是我无法弄清楚如何使用ActiveRecord接口将其合并为一个:

MonthlyCouponCounter.select("coupon_campaigns.id as coupon_campaign_id").joins(coupon: :coupon_campaign).where(coupon_campaigns: { id: [11,12,13] }).group("coupon_campaigns.id")

如果我运行此代码,则会收到以下错误:

  MonthlyCouponCounter Load (2.2ms)  SELECT coupon_campaigns.id as coupon_campaign_id FROM `monthly_coupon_counters` INNER JOIN `coupons` ON `coupons`.`id` = `monthly_coupon_counters`.`coupon_id` INNER JOIN `coupon_campaigns` ON `coupon_campaigns`.`id` = `coupons`.`coupon_campaign_id` WHERE `coupon_campaigns`.`id` IN (11, 12, 13) GROUP BY coupon_campaigns.id
(Object doesn't support #inspect)

编辑:我也试过这个并得到同样的错误

MonthlyCouponCounter.select("coupons.name as coupon_name").joins(:coupon).where(coupons: {id: 11})

0 个答案:

没有答案