Skip to content

Add example for usage with Postgres jsonb columns #44

@Jurawa

Description

@Jurawa

Just wanted to let you know I had some issues getting this setup when using a Postgres jsonb column...

My first implementation did not include a custom coder, and when updating a typed_store attribute, I got this error:

ActiveRecord::StatementInvalid: PG::InvalidTextRepresentation: ERROR:  invalid input syntax for type json
DETAIL:  Token "-" is invalid.
CONTEXT:  JSON data, line 1: -...
: UPDATE "companies" SET "settings" = $1, "updated_at" = $2 WHERE "companies"."id" = $3

Which is because it was using the default yaml coder.

However, when I added the DumbCoder, I got a TypeError: can't cast Hash to error.

It was all solved by just using the JSON coder:

typed_store :settings, coder: JSON do |s|
    s.boolean :foo, default: true, null: false
end

I think this would be useful to add to the readme...

Cheers!

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions