I'm trying to find all recipes in a certain category, where the key/value data is recorded in a PostgreSQL's jsonb column (and the value is saved as an array).
For example, say I have "data" as my jsonb column in the "recipes" table, and I have three entries like so:
"Recipe 1" contains a "data" with key/value of: "category_ids"=>[123, 4059]
"Recipe 2" contains a "data" with key/value of: "category_ids"=>[405, 543]
"Recipe 3" contains a "data" with key/value of: "category_ids"=>[567, 982]
I want to retrieve only items that contain the "405" category id value (i.e. only Recipe 2 above)
This is what I have so far using Ruby on Rails to query the PostgreSQL database:
Recipe.where("(data ->> 'category_ids') LIKE '%405%'")
However, that retrieves both "Recipe 1" and "Recipe 2" because they both contain "405" text.
What query should I use to correctly retrieve recipes with the "405" category id only?