我想创建一个具有数组属性的Sequel::Model
。我在表中添加了varchar[]
列,我可以使用Sequel::Dataset::update
成功更新记录。但是,如果我尝试在模型实例上设置属性并保存它,我会收到错误:
2.1.1 :048 > a = Sequel.pg_array(['public'])
=> ["public"]
2.1.1 :049 > DB[:oauth_access_tokens].where(id: 1).update(scopes: a)
I, [2014-06-19T09:53:49.009563 #40260] INFO -- : (0.003404s) UPDATE "oauth_access_tokens" SET "scopes" = ARRAY['public'] WHERE ("id" = 1)
=> 1
2.1.1 :050 > token = AccessToken.find(id: 1)
I, [2014-06-19T09:53:52.438038 #40260] INFO -- : (0.000771s) SELECT * FROM "oauth_access_tokens" WHERE ("id" = 1) LIMIT 1
=> #<AccessToken @values={:id=>1, :resource_owner_id=>2, :application_id=>1, :token=>"ec73426e2be81ab4772e67e139430d3896d705bcee6c141a38bd0e903e5df3eb", :refresh_token=>nil, :expires_in=>7200, :revoked_at=>nil, :created_at=>2014-06-06 12:37:07 -0400, :scopes=>["public"]}>
2.1.1 :051 > token.scopes = a
=> ["public"]
2.1.1 :052 > token.save
I, [2014-06-19T09:54:02.261076 #40260] INFO -- : (0.000332s) BEGIN
E, [2014-06-19T09:54:02.262007 #40260] ERROR -- : PG::InvalidTextRepresentation: ERROR: missing dimension value
LINE 1: ..." = '2014-06-06 12:37:07.485542-0400', "scopes" = '["public"...
^: UPDATE "oauth_access_tokens SET "resource_owner_id" = 2, "application_id" = 1, "token" = 'ec73426e2be81ab4772e67e139430d3896d705bcee6c141a38bd0e903e5df3eb', "refresh_token" = NULL, "expires_in" = 7200, "revoked_at" = NULL, "created_at" = '2014-06-06 12:37:07.485542-0400', "scopes" = '["public"]' WHERE ("id" = 1)
I, [2014-06-19T09:54:02.262691 #40260] INFO -- : (0.000229s) ROLLBACK
Sequel::DatabaseError: PG::InvalidTextRepresentation: ERROR: missing dimension value
LINE 1: ..." = '2014-06-06 12:37:07.485542-0400', "scopes" = '["public"...
使用Sequel对postgres数组类型的支持,我想做什么?如果是这样,我如何才能将token.scopes
设置为Array
或Sequel::Postgres::PGArray
并成功保存模型?
答案 0 :(得分:0)
This question似乎是同一个问题。看起来需要一个扩展才能实现,a look at this documentation。
编辑:根据to this,添加Sequel::Model.db.extension :pg_array
可能会有效吗?