开发者

Why is my ORDER BY clause being duplicated with this ActiveRecord scope?

开发者 https://www.devze.com 2023-02-26 07:39 出处:网络
I have this model: class Coupon < ActiveRecord::Base default_scope order(:created_at) scope :inactive, where(:active => false)

I have this model:

class Coupon < ActiveRecord::Base

  default_scope order(:created_at)
  scope :inactive, where(:active => false)

end

I'm seeing some weird duplication of the ORDER BY clause when using the inactive scope:

> Coupon.scoped.to_sql
 => "SELECT `coupons`.* FROM `coupons` ORDER BY `coupons`.`created_at`" 
> Coupon.inactive.to_sql
 => "SELECT `coupons`.* FROM `coupons` WHERE (`coupons`.`active` = 0) ORDER BY `coupons`.`created_at`, `coupons`.`created_at`"

This one really has me scratching my head. I'm using the MetaWhere gem if that's relevant.

U开发者_开发技巧pdate: I've isolated this to a MetaWhere bug. Doesn't happen with vanilla ActiveRecord.


Bundler was pulling down meta_where 0.9.9.2. Upgrading to ~> 1.0 fixes the issue.

0

精彩评论

暂无评论...
验证码 换一张
取 消

关注公众号