Rails 4.2.1 using mysql2 gem. ActiveRecord treats a mysql column with data type tinyint(1)
as a boolean. But I want to use it as a small number - I want to store values up to 100 which is ok for tinyint(1)
. When I try to create a record, the tinyint column casts to false
and I get a depreciation warning:
> Foo.create(my_tinyint_col: 13)
(0.2ms) BEGIN
SQL (0.5ms) INSERT INTO `foos` (`my_tinyint_col`) VALUES (0)
(107.3ms) COMMIT
=> #<Foo ID: 519, my_tinyint_col: false>
DEPRECATION WARNING: You attempted to assign a value which is not explicitly
true
orfalse
to a boolean column. Currently this value casts tofalse
. This will change to match Ruby's semantics, and will cast totrue
in Rails 5. If you would like to maintain the current behavior, you should explicitly handle the values you would like cast tofalse
.
If i change the data definition of my_tinyint_col
to tinyint(2)
the problem goes away - but is there a way to treat tinyint(1)
as a number using ActiveRecord?