迁移:
class Preference < ActiveRecord::Migration
def change
enable_extension 'hstore'
create_table :preferences do |t|
t.hstore :prefs
end
end
end
型号:
class Preference < ActiveRecord::Base
store_accessor :prefs
end
如果prefs是一个像{ email:'yes' }
这样的哈希表,则此方法似乎有效,但对于包含数组的哈希表,则不起作用:{ email:[ 'monday', 'tuesday' ]}
。
在提取哈希表时,该数组被保存为JSON。
有没有一种好的方法来使用具有嵌套哈希和数组的hstore?
我尝试在迁移中添加array:true
,但这只允许保存数组而不是哈希表。
如何将Rails PostgreSQL hstore与嵌套哈希和数组一起使用?
Rails 4.2.4,PostgreSQL 9.3.5
jsonb
,对吧? - mu is too short