V6: Unable to select pivot columns #4744
Unanswered
simonjcarr
asked this question in
Help
Replies: 1 comment 1 reply
-
I have realised now, that I only get to see the pivot colums when I access the organisation object in the result. This means I need to map over my results and access the $attributes and $extras manually. async index({ response, auth }: HttpContext) {
// Get the users organisations and return them
const user = auth.user
const orgs = await user?.related('organisation').query()
return response.json(
orgs?.map((org) => {
return {
...org.$attributes,
role: org.$extras.pivot_role,
}
})
)
} Is there a cleaner way to do this? |
Beta Was this translation helpful? Give feedback.
1 reply
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Uh oh!
There was an error while loading. Please reload this page.
Uh oh!
There was an error while loading. Please reload this page.
-
I have the following two models User and Organisation where I declaser my ManyToMany relationship
I have the following organisation_users schema
When I try to select User and preload organisation with the following
The $extras is empty
The user and the organisation are returned correctly, and I do have data in my pivot column. See the attached image.

I also tried to create a Model for the pivot table, but that made no difference.
Beta Was this translation helpful? Give feedback.
All reactions