1

The following query works fine.

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

But I can't figure out how to make this into one using ActiveRecord interface:

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

If I run this code, I get the following error:

  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)

EDIT: I also tried this and gets the same error

MonthlyCouponCounter.select("coupons.name as coupon_name").joins(:coupon).where(coupons: {id: 11})
nextofsearch
  • 366
  • 3
  • 10
  • Possible duplicate of [(Object doesn't support #inspect)](http://stackoverflow.com/questions/7690697/object-doesnt-support-inspect) – Ilya Mar 30 '17 at 11:21
  • @Ilya I already checked other questions but none helps. – nextofsearch Mar 30 '17 at 11:50
  • I suspect this has nothing to do with the sequel but is because the rails console calls `inspect` on the result of the command. There probably wouldn't be an error if you added something like `.present?` to the end of the command. Does `MonthlyCampaignCounter.first` work? What do your models look like? – Marc Rohloff Mar 30 '17 at 21:12

0 Answers0