I'm trying to create a model that uses a boolean type, supported by
mysql engine. My generate is like so:

./script/generate model Product name:string vendor_id:integer
in_stock:boolean

However, when I try to play with the console and save products to the
database, only products defined with in_stock = true or in_stock = 1 are
successfully saved. I can't seem to save items with a false value.
Here's what I mean:

>> p = Product.new(:name => "VCR", :vendor_id => 1, :in_stock => true)
=> #<Product id:nil, name: "VCR", vendor_id: 1, in_stock: true,
created_at....>
>> p.save
=> true

This also works with :in_use => 1

vHowever, all these fail:

>> p = Product.new(:name => "VCR", :vendor_id => 1, :in_stock => false)
>> p.save
=> false
>> p = Product.new(:name => "VCR", :vendor_id => 1, :in_stock => 0)
>> p.save
=> false
>> p = Product.new(:name => "VCR", :vendor_id => 1, :in_stock => nil)>> p.save
=> false

The migration lists the type as t.boolean :in_use, and the database
shows the column type as tinyint(1).

What am I doing wrong?

Thanks!
-- 
Posted via http://www.ruby-forum.com/.

--~--~---------~--~----~------------~-------~--~----~
You received this message because you are subscribed to the Google Groups "Ruby 
on Rails: Talk" group.
To post to this group, send email to [email protected]
To unsubscribe from this group, send email to 
[email protected]
For more options, visit this group at 
http://groups.google.com/group/rubyonrails-talk?hl=en
-~----------~----~----~----~------~----~------~--~---

Reply via email to