如标题所示,我尝试将哈希编入 hstore 类型列。
我见过带有 hstore 属性的问题制造者,但那里的解决方案对我不起作用。
我的 hstore 列名是“status”,我想设置三个标志:“processed”、“duplicate”、“eol”。我正在使用续集(4.14.0)作为 ORM、制造(2.8.1)、Ruby 2.1.2 和 Postgresql,当然;)
情况1:
status {eol: true, duplicate: false, processed: true}
结果:
语法错误
案例2:
status {"heol"=>"true", "hduplicate"=>"false", "hprocessed"=>"true"}
结果:
语法错误
案例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' = '. .. 提示:您将需要重写或强制转换表达式。
案例4:
status do
{status: "heol:true"}
end
结果:
失败/错误:Fabricate(:entry) Sequel::DatabaseError: PG::UndefinedColumn: ERROR: column "status" does not exist LINE 1: ...123.0, '2000-01-01', ("status" =. .. 提示:表“entries”中有一个名为“status”的列,但不能从这部分查询中引用它。
案例5:
状态做 {'status' => "heol:true"} 结束
结果:
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
承诺在 Fabrication 中充分利用正确的语法 =) 谢谢!
卢卡斯。