I make a custom query that returns rows with array value term_names
Product.connection.select_all("
SELECT ARRAY_AGG(terms.name), vocabularies.name vocabulary_name
FROM terms
INNER JOIN vocabularies ON vocabularies.id = terms.vocabulary_id
GROUP BY vocabulary_name")
| term_names | vocabulary_name |
|----------------------------------------------------------------|-----------------|
| {{76,Yellow},{77,Green},{79,Blue}. | Color |
But the problem is that Rails does not want to convert {...} into ruby array and returns it as string.
[{"array_agg"=>"{Yellow,Green,Blue}", "vocabulary_name"=>"Color"}]
How can I make Rails parse result and return nested array instead?
split, and/or set up a model to talk to the "terms" table, then use ruby to do the grouping