Cat.find_by("toy->>'model' = ?", my_model)
There are two operators for JSONB in Postgres:
->
: returns JSONB->>
: returns a string
If you need to dig into an object use ->
. For the last access use ->>
to return a string:
Cat.find_by("toy->'details'->>'model' = ?", my_model)