This project is archived and is in readonly mode.

#6079 ✓resolved
Brian Underwood

Serialize saves false boolean value as string "f" in sqlite3

Reported by Brian Underwood | November 28th, 2010 @ 07:45 PM | in 3.0.5

I notice that when I have a sample model such as this:

   class Foo < ActiveRecord::Base
     serialize :data
   end

If I try to save the boolean value "true" to the "data" field, it works fine, but when I try to save the boolean value "false", it saves it as the string "f":

   ruby-1.9.2-p0 >       ActiveRecord::Base.logger = Logger.new(STDOUT)
   ...
   ruby-1.9.2-p0 > f = Foo.first
     Foo Load (0.2ms)  SELECT "foos".* FROM "foos" LIMIT 1
    => #<Foo id: 1, data: true, created_at: "2010-11-28 19:11:05", updated_at: "2010-11-28 19:13:16"> 
   ruby-1.9.2-p0 > f.data = false
    => false 
   ruby-1.9.2-p0 > f.save
     AREL (0.5ms)  UPDATE "foos" SET "data" = 'f', "updated_at" = '2010-11-28 19:25:02.547106' WHERE ("foos"."id" = 1)

It seems that this is an issue where type casting shouldn't apply to serialized fields. Could this be fixed simply? (I poked around in the Rails source for a bit without much luck on how to get started. Plus I'm not sure if this is limited to sqlite3 or if it's in other drivers).

Using Rails 3.0.3 and Ruby 1.9.2-p0 in RVM on Mac OS 10.6.5 (FWIW)

Comments and changes to this ticket

Create your profile

Help contribute to this project by taking a few moments to create your personal profile. Create your profile »

<h2 style="font-size: 14px">Tickets have moved to Github</h2>

The new ticket tracker is available at <a href="https://github.com/rails/rails/issues">https://github.com/rails/rails/issues</a>

Attachments

Referenced by

Pages