Rails active record's 'where' method anomaly

Viewed 40

I tried the following statement in the rails console:

SomeModel.where(["active = ? and price = ? and status_date <= ?", true , nil , Date.parse('20161101')]).size

This gave me >> 0

Then I modified the above statement to this:

SomeModel.where([ "active = ? and status_date <= ?", true , Date.parse('20161101') ]).where(price: nil).size

This gave me >> 533

Can someone explain why is this happening? Why aren't these two statements giving the same output?

Specs: Rails 5.0.0, Postgres

1 Answers
Related