6
votes

I'm fairly new to AREL, and have had trouble finding references to using Postgres JSONB with AREL.

How might I convert this SQL into an AREL statement?

SELECT
    tag,
    count(tag)
FROM
    people p,
    jsonb_array_elements(p.data->'tags') tag 
WHERE p.data->'tags' ? '#{tag}' 
GROUP BY tag
You may find the ActiveRecordExtended gem helpfuleikes