【发布时间】:2014-09-06 20:03:23
【问题描述】:
如标题所示,我尝试将哈希编入 hstore 类型列。
我看到了问题fabricator with hstore attribute,但那里的解决方案对我不起作用。
我的 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
结果:
续集::数据库错误: PG::DatatypeMismatch:错误:列“状态”是 hstore 类型,但表达式是布尔类型 第 1 行:...23.0, '2000-01-01', (('heol' = '... 提示:您需要重写或强制转换表达式。
案例 4:
status do
{status: "heol:true"}
end
结果:
失败/错误:Fabricate(:entry) 续集::数据库错误: PG::UndefinedColumn:错误:列“状态”不存在 第 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 中的正确语法 =) 谢谢!
卢卡斯。
【问题讨论】:
标签: postgresql rspec sequel hstore fabrication-gem