Read JSON::Any Columns as .to_json
'd String
#467
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Greetings 👋
Submitting this small PR as I recently ran into an issue when using
import
for a model. If I created the model one-off and used.new
(add attribute values) then.save
, the model would save just fine. If I instead set up a bunch of models then used.import
, I'd get an error that stemmed down to this issue.The short of it is that each adapter's
import
(pg's here) callsread_attribute
under the hood and passes the then-read value along to the query builder but does so with its native type. If you ask a model for the value of aJSON::Any
-typed column, you'll get aJSON::Any
typed value. The query builder doesn't like that type though and will error.This PR injects a
.to_json
in the process for any column whose type includesJSON::Any
. This does indeed convert the value to a string and makes the query builder happy, but this PR may well be a proof of concept. There is definitely a better way of doing this, and this may overall be a stop-gap where correctly wiring up the Granite Converter(s) could be the right choice. Submitting this to explain my story, give some context, and hopefully inspire a better path forward!Cheers!