jeudi 30 juin 2016

group by and filter in rails

I have a model Article in mydb

+----+------------------------+
| id | keywords               |
+----+------------------------+
| 83 | automotive, pet, heath |
| 82 | car, plane             |
| 81 | NULL                   |
| 80 | pet, car               |
| 78 | Null                   |
+----+------------------------+

I want t get result same as:

{
"automotive" => [82], 
"pet" => [82,80], 
"heath" => [83], 
"plane" => [82], 
"car" => "80" 
}

how do i get result same as data above??

Aucun commentaire:

Enregistrer un commentaire