问题
As per the api docs:
If you wish to disable this emulation (which was the default behavior in versions 0.13.1 and earlier) you can add the following line to your application.rb file:
ActiveRecord::ConnectionAdapters::Mysql[2]Adapter.emulate_booleans = false
But when I do so, I get:
uninitialized constant ActiveRecord::ConnectionAdapters::Mysql2Adapter
回答1:
For someone see this topic later, I needed to require mysql2_adapter with full path in Rails 3.2.0;
module MyApp
class Application < Rails::Application
require 'active_record/connection_adapters/mysql2_adapter'
ActiveRecord::ConnectionAdapters::Mysql2Adapter.emulate_booleans = false
end
end
回答2:
I had the same issue that I think you had. But in my case I didn't want to turn off the tinyint emulates but only set some tinyint columns of a legacy database as Integer type and not boolean type. Searching, I found a solution to my problem. Matt Jones¹ showed the Rails code documentation² explaining how to:
class SomeModel < ActiveRecord::Base
attribute :a_tinyint_1_column_that_isnt_a_boolean, Type::Integer.new
end
¹ https://www.ruby-forum.com/topic/201859
² https://github.com/rails/rails/blob/daffea59db118fce4247d335eabea026cc54d7bc/activerecord/lib/active_record/attributes.rb#L17
回答3:
The docs don't ask you to require activerecord in application.rb. Requiring it solved the problem.
来源:https://stackoverflow.com/questions/10038665/how-do-i-turn-off-tinyint-boolean-emulation-in-rails-3-2-2