Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Can't query columns #82

Closed
ManuelFrigerio opened this issue Aug 18, 2020 · 1 comment
Closed

Can't query columns #82

ManuelFrigerio opened this issue Aug 18, 2020 · 1 comment

Comments

@ManuelFrigerio
Copy link

Hi,

I have the following column in my User table:

typed_store :onboarding_questions, coder: ActiveRecord::TypedStore::IdentityCoder do |s|
    s.string :esp
    s.string :signup_source
    s.string :newsletter_list_size
    s.string :main_challenge
    s.string :newsletter_monetization
  end

The onboarding_questions column is of type JSON.

However, when I try to query the User table

User.where(esp: "convertkit").count

I get an error:

ActiveRecord::StatementInvalid (PG::UndefinedColumn: ERROR:  column users.esp does not exist
LINE 1: SELECT COUNT(*) FROM "users" WHERE "users"."esp" = $1
                                           ^
)

What am I doing wrong?

Thanks

@casperisfine
Copy link
Collaborator

That's a PostgreSQL / Active Record question, it doesn't have much to do with typedstore. To query JSON field you need to use the Postgres specific syntax, e.g. first Google result: https://makandracards.com/makandra/37851-how-to-query-postgresql-s-json-fields-from-rails

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants