sqlite3 - sqlite boolean 't' and 'f' with rails active record -


i use mysql on production , sqlite3 on development.

when querying database on development e.g.

@follow_ups = followup.where(is_complete: false) 

i sql below in console

select "follow_ups".* "follow_ups"  "follow_ups"."is_complete" = 'f' 

sqlite evaluates 'f' truthy value no follow_ups.is_complete = false returned. in database stored true/false. investigations found.

https://github.com/rails/rails/issues/10720
rails 3 sqlite3 boolean false

what should boolean filters working? have thought happening more people.

see schema below

  create_table "follow_ups", force: true |t|     t.integer  "contact_id"     t.integer  "owner_id"     t.datetime "due_date"     t.string   "comment"     t.boolean  "is_complete",        default: false     t.integer  "created_by_user_id"     t.integer  "updated_by_user_id"     t.datetime "created_at"     t.datetime "updated_at"   end 

see data , insertions below - done via rails console. request in comments.

[30] pry(main)> followup.create(contact_id: 1, due_date: time.now, is_complete: true)    (0.1ms)  begin transaction   sql (0.4ms)  insert "follow_ups" ("contact_id", "created_at", "due_date", "is_complete", "updated_at") values (?, ?, ?, ?, ?)  [["contact_id", 1], ["created_at", "2014-04-22 19:17:01.854402"], ["due_date", "2014-04-22 19:17:01.853540"], ["is_complete", "t"], ["updated_at", "2014-04-22 19:17:01.854402"]]    (1.7ms)  commit transaction #<followup:0x0000010699c5a8> {                     :id => 23,             :contact_id => 1,               :owner_id => nil,               :due_date => tue, 22 apr 2014 19:17:01 utc +00:00,                :comment => nil,            :is_complete => true,     :created_by_user_id => nil,     :updated_by_user_id => nil,             :created_at => tue, 22 apr 2014 19:17:01 utc +00:00,             :updated_at => tue, 22 apr 2014 19:17:01 utc +00:00 } [31] pry(main)> followup.where(is_complete: true)   followup load (0.3ms)  select "follow_ups".* "follow_ups"  "follow_ups"."is_complete" = 't' #<activerecord::relation [#<followup id: 16, contact_id: 1, owner_id: 1, due_date: "2014-04-23 00:00:00", comment: "lorem ipsum dolor sit amet, consectetur adipisicin...", is_complete: true, created_by_user_id: 1, updated_by_user_id: 1, created_at: "2014-04-17 09:57:00", updated_at: "2014-04-22 14:37:36">, #<followup id: 23, contact_id: 1, owner_id: nil, due_date: "2014-04-22 19:17:01", comment: nil, is_complete: true, created_by_user_id: nil, updated_by_user_id: nil, created_at: "2014-04-22 19:17:01", updated_at: "2014-04-22 19:17:01">]> [32] pry(main)> followup.where(is_complete: false)   followup load (0.2ms)  select "follow_ups".* "follow_ups"  "follow_ups"."is_complete" = 'f' #<activerecord::relation []> [33] pry(main)> followup.all   followup load (0.2ms)  select "follow_ups".* "follow_ups" #<activerecord::relation [#<followup id: 16, contact_id: 1, owner_id: 1, due_date: "2014-04-23 00:00:00", comment: "lorem ipsum dolor sit amet, consectetur adipisicin...", is_complete: true, created_by_user_id: 1, updated_by_user_id: 1, created_at: "2014-04-17 09:57:00", updated_at: "2014-04-22 14:37:36">, #<followup id: 17, contact_id: 1, owner_id: 1, due_date: "2014-04-24 00:00:00", comment: "this ia  long comment", is_complete: false, created_by_user_id: 1, updated_by_user_id: 1, created_at: "2014-04-17 10:04:13", updated_at: "2014-04-17 10:04:13">, #<followup id: 18, contact_id: 1, owner_id: 1, due_date: "2014-04-24 00:00:00", comment: "this comment\r\n", is_complete: false, created_by_user_id: 1, updated_by_user_id: 1, created_at: "2014-04-17 10:24:05", updated_at: "2014-04-17 10:24:05">, #<followup id: 19, contact_id: 1, owner_id: 1, due_date: "2014-04-23 00:00:00", comment: "test", is_complete: false, created_by_user_id: 1, updated_by_user_id: 1, created_at: "2014-04-22 13:37:40", updated_at: "2014-04-22 13:37:40">, #<followup id: 20, contact_id: 1, owner_id: 1, due_date: "2014-04-23 00:00:00", comment: "test", is_complete: false, created_by_user_id: 1, updated_by_user_id: 1, created_at: "2014-04-22 13:37:41", updated_at: "2014-04-22 13:37:41">, #<followup id: 21, contact_id: 1, owner_id: 1, due_date: "2014-04-24 00:00:00", comment: "test", is_complete: false, created_by_user_id: 1, updated_by_user_id: 1, created_at: "2014-04-22 13:39:20", updated_at: "2014-04-22 13:39:20">, #<followup id: 22, contact_id: 2, owner_id: 1, due_date: "2014-04-30 00:00:00", comment: "test", is_complete: false, created_by_user_id: 1, updated_by_user_id: 1, created_at: "2014-04-22 13:53:37", updated_at: "2014-04-22 13:53:37">, #<followup id: 23, contact_id: 1, owner_id: nil, due_date: "2014-04-22 19:17:01", comment: nil, is_complete: true, created_by_user_id: nil, updated_by_user_id: nil, created_at: "2014-04-22 19:17:01", updated_at: "2014-04-22 19:17:01">]> 

in sqlite3, boolean value not supported. rails use char 't' , 'f' represent boolean value true , false. while in other database mysql, postgresql, real boolean value true , false used.

however, difference transparent rails model. can use

followup.where(is_compete: true) 

to filter completed followups and

followup.where(is_compete: false) 

to incomplete followups


Comments

Popular posts from this blog

java - Intellij Synchronizing output directories .. -

git - Initial Commit: "fatal: could not create leading directories of ..." -