I am attempting to upgrade my code from ActiveRecord 3 to ActiveRecord 4, and I believe I have encountered a bug/regression in the boolean query support for ActiveRecord + SQLite3.
Here is the output of an IRB session running ActiveRecord 4.0.2 where SQLite3 is the database back-end:
2.0.0p353 :040 > StoreItem.where(item_class: 1, enabled: 1).order(item_order: :desc).count
=> 4
2.0.0p353 :041 > StoreItem.where(item_class: 1, enabled: true).order(item_order: :desc).count
=> 0
As a point of comparison, here is the same output when Mysql 5.5 is the database back-end:
2.0.0p353 :005 > StoreItem.where(item_class: 1, enabled: 1).order(item_order: :desc).count
=> 4
2.0.0p353 :006 > StoreItem.where(item_class: 1, enabled: true).order(item_order: :desc).count
=> 4
Now, let's see what happens when running with AR 3.2.14:
SQLite3:
2.0.0p353 :005 > StoreItem.where(item_class: 1, enabled: 1).order(item_order: :desc).count
=> 0
2.0.0p353 :006 > StoreItem.where(item_class: 1, enabled: true).order(item_order: :desc).count
=> 4
Mysql 5.5:
2.0.0p353 :001 > StoreItem.where(item_class: 1, enabled: 1).order(item_order: :desc).count
=> 4
2.0.0p353 :002 > StoreItem.where(item_class: 1, enabled: true).order(item_order: :desc).count
=> 4
As you can see, ActiveRecord 3.2.14 and 4.0.2 do the exact opposite thing in SQLite3 when presented with boolean queries.
I just checked the actual generated SQL and it is identical. The first query looks like this:
SELECT COUNT(*) FROM "store_items" WHERE "store_items"."item_class" = 1 AND "store_items"."enabled" = 1
The second looks like this:
SELECT COUNT(*) FROM "store_items" WHERE "store_items"."item_class" = 1 AND "store_items"."enabled" = 't'
Thus, perhaps there has been a change in SQLite3 from 1.3.5 to 1.3.8 in its treatment of boolean column values?
Is this a known bug, and can anyone comment on the cause?