Cat.find_by("toy->>'model' = ?", my_model)

There are two operators for JSONB in Postgres:

  1. ->: returns JSONB
  2. ->>: 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)