many-to-one selection as array

Hi,

Let's say I have a user table, and the user can have multiple profiles. When I select using join on user_id I get back two records like so (pseudo-code):

[
  { user_id: 123, profile_id: "abc" },
  { user_id: 123, profile_id: "def" },
]


What I want is a single record, where profiles are listed in an array on the user object:

[
  {
    user_id: 123,
    profiles: [
      { profile_id: "abc" },
      { profile_id: "def" },
    ]
  }
]


Is there an elegant way for me to get query back in desired form (w/o needing to resort to two queries and patching together a new type)? Any help is much appreciated!

Thanks,
Was this page helpful?