Is there a lightweight way of doing something like this?
Foo.order(:bar => [true, false, nil]).map{|f| f.bar}.uniq
=> [true, false, nil]
Foo.order(:bar => [true, false, nil]).class
=> Foo::ActiveRecord_Relation
The following aren't what I want:
Foo.order(:bar).map{|f| f.bar}.uniq
=> [false, true, nil]
Foo.order("bar DESC").map{|f| f.bar}.uniq
=> [nil, true, false]
Found the answer:
Foo.order("bar DESC NULLS LAST").map{|f| f.bar}.uniq
=> [true, false, nil]
Foo.order("bar DESC NULLS LAST").class
=> Foo::ActiveRecord_Relation
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With