就像在标题中一样,我尝试将哈希制作成hstore类型的列。为Postgresql制作hstore值
我看过问题fabricator with hstore attribute,但是那里的解决方案并不适合我。
我的hstore列名称是“状态”,那里我想设置三个标志:“已处理”,“重复”,“EOL”。我使用续集(4.14.0)作为ORM,制造(2.8.1),红宝石2.1.2当然PostgreSQL的)
壳体1:
status {eol: true, duplicate: false, processed: true}
结果:
syntax error
壳体2:
status {"heol"=>"true", "hduplicate"=>"false", "hprocessed"=>"true"}
结果:
syntax error
壳体3:
status do
{"heol"=>"true", "hduplicate"=>"false", "hprocessed"=>"true"}
end
结果:
Sequel::DatabaseError: PG::DatatypeMismatch: ERROR: column "status" is of type hstore but expression is of type boolean LINE 1: ...23.0, '2000-01-01', (('heol' = '... HINT: You will need to rewrite or cast the expression.
壳体4:
status do
{status: "heol:true"}
end
结果:
Failure/Error: Fabricate(:entry) Sequel::DatabaseError: PG::UndefinedColumn: ERROR: column "status" does not exist LINE 1: ...123.0, '2000-01-01', ("status" =... HINT: There is a column named "status" in table "entries", but it cannot be referenced from this part of the query.
壳体5:
status do {'status' => "heol:true"} end
结果:
Failure/Error: Fabricate(:entry) Sequel::DatabaseError: PG::DatatypeMismatch: ERROR: column "status" is of type hstore but expression is of type boolean LINE 1: ...123.0, '2000-01-01', ('status' =... HINT: You will need to rewrite or cast the expression.
壳体6: 放弃) 结果: 这个问题
随着FactoryGirl一切正常,和语法很简单:
FactoryGirl.define do
factory :entry do
status {{ flag_processed: true, flag_duplicate: false }}
end
承诺要利用好正确的语法在制作=) 谢谢!
卢卡斯。
它的工作完美,谢谢! – CloudRide 2014-09-06 20:37:34
请注意:要使用Sequel.hstore方法,您需要在数据库实例(DB)上启用Sequel的pg_hstore扩展: DB.extension:pg_hstore – CloudRide 2014-09-06 20:39:04