2

I want to create a Sequel::Model that has an array attribute. I have added a varchar[] column to the table, and I can successfully update records using Sequel::Dataset::update. However, if I try to set the attribute on a model instance and save it, I get an error:

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"...

Is what I want to do even possible with Sequel's support for postgres array types? If so, how can I allow setting token.scopes to either an Array or a Sequel::Postgres::PGArray and successfully save the model?

1 Answer 1

0

This question seems like the same issue. It looks like there is an extension needed for this to work, take a look at this documentation.

edit: According to this, maybe adding Sequel::Model.db.extension :pg_array will do the trick?

Sign up to request clarification or add additional context in comments.

3 Comments

Not the same issue; I'm using the extension already (as you can see from the invocation of the Sequel.pg_array method)
Found something else that may be of value in that case... See edit.
Still the case that using the extension isn't the problem. I can use the extension just fine to update the database if I go through the dataset interface. The problem is the extension does not seem to integrate with the Sequel::Model class.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.