Problem serializing Postgres' array columns due to delegation. #2153
Replies: 2 comments 2 replies
-
I don't think something is built into Sequel that will do what you want. Having the access method return the underlying array instead of the wrapper could definitely break things in certain cases (though maybe not cases that would affect you). I've never used Oj, so I don't know how much control it gives over the dumping process. It would be best to fix the issue in Oj, since the problem is Oj not handling delegate objects as you want (this isn't a Sequel-specific issue, it likely affects any use of the delegate classes using the stdlib delegate library). Does setting the |
Beta Was this translation helpful? Give feedback.
-
I know this doesn't directly answer your question, but we use PG array columns and |
Beta Was this translation helpful? Give feedback.
Uh oh!
There was an error while loading. Please reload this page.
Uh oh!
There was an error while loading. Please reload this page.
-
Hi!
We are currently working with Sequel as our ORM, Postgres as our DBMS and Oj for dumping objects to JSON. This works fine on most use cases but we recently started using array type columns and started experiencing some issues.
For example, if we have this table
and the model (the
pg_array
extension is already loaded)when accesing the column we get:
but that's not an array, it's a
PGArray
that delegates toArray
. This causes a problem when dumping with Oj, as that gem serializes the instance variables of the object that is being dumped, and we getwhich is not the expected result. We checked the source code of the extension from where we got the idea to try to solve this issue by registering a conversion proc with
add_conversion_proc
, but without success. We also tried different option on the dumping of Oj, mainlyuse_to_hash
anduse_to_json
but this didn't help.The current solution we are using is to explicitly get the delegate object of the column on the accesor
which works, but we would rather not have to override that for every array column of every model.
Is there any mechanism in Sequel that might help us solve this issue? Maybe a way to wrap the accesors methods of every column of every model for a specific type or something like that?
Thanks!
Beta Was this translation helpful? Give feedback.
All reactions