Warning: file_get_contents(/data/phpspider/zhask/data//catemap/1/cassandra/3.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Ruby on rails hstore的Rails Postgresql数组_Ruby On Rails_Hstore - Fatal编程技术网

Ruby on rails hstore的Rails Postgresql数组

Ruby on rails hstore的Rails Postgresql数组,ruby-on-rails,hstore,Ruby On Rails,Hstore,somoone是否知道在rails 4中是否可能有hstore阵列?我试着 add_column :orders, :frozen_content, :hstore , array: true 但是我有 PG::Error: ERROR: malformed array literal: 当我试图保存时,您可以起诉activerecord postgres hstore gem: 从文档中: 创建一个hstore-backed字段: 类Personfoo'='bar')) Rails

somoone是否知道在rails 4中是否可能有hstore阵列?我试着

add_column :orders, :frozen_content, :hstore , array: true
但是我有

 PG::Error: ERROR:  malformed array literal: 

当我试图保存时,您可以起诉activerecord postgres hstore gem:

从文档中:

  • 创建一个hstore-backed字段:

    类Person
  • 向其中添加字段:

    person=person.new person.data['foo']='bar' 个人拯救

  • 查询:

    Perosn.where(“数据->foo'='bar'))

  • Railscast#345(位于付费墙后面)使用activerecord postgres hstore gem提供了更多详细信息:


    注意:我还没有尝试过rails 4。。。YMMV.

    您可以起诉activerecord postgres hstore gem:

    从文档中:

  • 创建一个hstore-backed字段:

    类Person
  • 向其中添加字段:

    person=person.new person.data['foo']='bar' 个人拯救

  • 查询:

    Perosn.where(“数据->foo'='bar'))

  • Railscast#345(位于付费墙后面)使用activerecord postgres hstore gem提供了更多详细信息:


    注意:我还没有尝试过rails 4。。。YMMV.

    原则上是的,但正如您所发现的,它在保存时没有正确转义。我今天刚刚记录了一个问题,请参见(包括一个补丁和一些演示代码)

    原则上是的,但您发现它在保存时没有正确转义。我今天刚刚记录了一个问题,请参阅(包括一个补丁和一些演示代码)

    这是一个至少存在于Rails 4.0.1中的错误

    ,但在合并之前,您可以使用monkey patch Rails:

    # config/initializers/extensions/postgres.rb
    module ActiveRecord
      module ConnectionAdapters
        class PostgreSQLColumn < Column
          module Cast
            private
    
              def quote_and_escape(value)
                case value
                when "NULL"
                  value
                else
                  "\"#{value.gsub(/(["\\])/, '\\\\\1')}\""
                end
              end
          end
        end
      end
    end
    

    这是一个至少存在于Rails 4.0.1中的错误

    ,但在合并之前,您可以使用monkey patch Rails:

    # config/initializers/extensions/postgres.rb
    module ActiveRecord
      module ConnectionAdapters
        class PostgreSQLColumn < Column
          module Cast
            private
    
              def quote_and_escape(value)
                case value
                when "NULL"
                  value
                else
                  "\"#{value.gsub(/(["\\])/, '\\\\\1')}\""
                end
              end
          end
        end
      end
    end
    

    我试着在这里做HSTORE数组。对于经典的Hstore列,我没有问题。我在这里尝试使用Hstore数组。对于经典的Hstore专栏,我没有问题,我不确定这是否是同一个问题。至少,我用另一个补丁修复了这个bug:我不确定这是否是同一个问题。至少,我用另一个补丁修复了这个bug:这个bug仍然存在于Rails 4.0.2中。希望他们能很快合并!该缺陷仍然存在于Rails 4.0.2中。希望他们能很快合并!