デフォルトではtrue。つまりtinyint(1) はbooleanとして扱うことになる。 tinyint(1) は0~255の値を扱えるのでこのままでは不都合が生じた。
解決策
- この設定をfalseにする
- activemodel側で再度キャストする
どちらもドキュメントにあるのね。
- アプリケーション全体で設定を無効にする
# config/application.rb
require 'active_record/connection_adapters/mysql2_adapter'
ActiveRecord::ConnectionAdapters::Mysql2Adapter.emulate_booleans = false
- Model単位
class StoreListing < ActiveRecord::Base
attribute :price_in_cents, Type::Integer.new
end