Query nested jsonb Postgres column
Ok, just found a way:
Model.where("(metadata -> 'bar' ->> 'baz') IS NOT NULL")
if metadata has more nested json:
obj.metadata = {"foo"=>"1", "bar"=>{"baz"=>{"qux"=>2}}}
and I would want to see, if there's metadata['bar']['baz']['qux']
:
Model.where("(metadata -> 'bar' -> 'baz' ->> 'qux') IS NOT NULL")