Rails 3 SQLite3 Boolean false

后端 未结 5 1924
太阳男子
太阳男子 2020-11-27 22:39

I\'m trying to insert a false boolean value in a SQLite3 table but it always inserts a true value.

Here\'s my migration:

class CreateUsers < Activ         


        
5条回答
  •  半阙折子戏
    2020-11-27 23:20

    This version works in Rails 4.1.

    require 'active_record/connection_adapters/sqlite_adapter'
    
    module ActiveRecord::ConnectionAdapters::SQLite3Adapter
      QUOTED_TRUE, QUOTED_FALSE = 't'.freeze, 'f'.freeze
    
      def quoted_true; QUOTED_TRUE end
      def quoted_false; QUOTED_FALSE end
    end
    

    The constants and .freeze are for performance, so ruby doesn't have to regenerate those strings and garbage collect them on every call.

提交回复
热议问题