2012-04-06 4 views
1
은 API 문서 당으로

:Rails 3.2.2에서 tinyint 부울 에뮬레이션을 해제하려면 어떻게합니까?

이 에뮬레이션 해제하고자하는 경우 (버전 0.13.1의 기본 동작이며 이전 버전) 당신이 당신의 application.rb 파일에 다음 줄을 추가 할 수 있습니다

ActiveRecord::ConnectionAdapters::Mysql[2]Adapter.emulate_booleans = false 
내가 그렇게 할 때

는하지만, 내가 얻을 : 워드 프로세서는 application.rb에서 액티브을 요구하도록 요구하지 않는

uninitialized constant ActiveRecord::ConnectionAdapters::Mysql2Adapter 
+1

추측 : AR 아마에서 요구되지 않았기 때문에 일부 잘못된 위치에 퍼팅 가능성 시간. – Zabba

+0

나는 문서가 요구하는 것과 똑같은 파일에 넣을 것입니다. –

+0

귀하의'application.rb' – MikDiet

답변

-1

. 그것을 요구하면 문제가 해결됩니다.

4

나중에이 항목을 참조하십시오. 전체 경로와 함께 mysql2_adapter를 요구해야했습니다. 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 
1

나는 당신과 같은 문제가 있다고 생각했습니다. 하지만 제 경우에는 tinyint를 끄기를 원하지 않았지만 레거시 데이터베이스의 일부 tinyint 열만을 정수 유형으로 설정하고 부울 유형은 설정하지 않았습니다. 검색 중, 내 문제에 대한 해결책을 찾았습니다. 매트 존스 ¹는 방법을 설명 documentation² 레일 코드를 보여 주었다 :

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

관련 문제