Format JOIN result object

1
[PROFESSORES]
id | nome     |

1  | Gilson   |


[CURSOS]
id | nome      | professor_id

1  | Photoshop | 1
2  | AutoCad   | 1

I would like the result of my SELECT to come in the format: (Not necessarily or exactly the same, I just want to group the result).

{
  id: 1,
  nome: 'gilson',
  CURSOS: [
    {
      id: 1,
      nome: 'Photoshop',
      professor_id: 1
    },
    {
      id: 2,
      nome: 'AutoCad',
      professor_id: 1
    }
  ]
}

Is there any way to do this grouping directly in Query, or just manipulating via code itself? (2 querys)

    
asked by anonymous 09.11.2015 / 18:12

0 answers