Format JOIN result object

Asked

Viewed 41 times

1

[PROFESSORES]
id | nome     |

1  | Gilson   |


[CURSOS]
id | nome      | professor_id

1  | Photoshop | 1
2  | AutoCad   | 1

I would like that in the result of my SELECT, the object comes 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 ? (2 querys)

No answers

Browser other questions tagged

You are not signed in. Login or sign up in order to post.