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.
Update: 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.