Many-to-many relationship and pivot columns. #261
-
Hi, I'm trying to build a many-to-many relationship by customizing with this relationships:
users:
- name: "users-organizations"
sides:
- from: "users"
to: "organization_user"
columns: [[id, user_id]]
- from: "organization_user"
to: "organizations"
columns: [[organization_id, id]] It works well by returning the related organizations for users but I want to access more fields on the |
Beta Was this translation helpful? Give feedback.
Replies: 2 comments
-
Couldn't you just select the E.g. If that's not what you need a bit more context would be helpful like the structure of your tables and what kind of query you want to do. |
Beta Was this translation helpful? Give feedback.
-
The complexity of trying to If I understand correctly what you're trying to do, you have a few options: 1. Have two separate relationships.
models.Users.Query(
models.ThenLoadUserOrganizationUsers(
sm.Columns(...), // filter the join table columns
models.PreloadOrganizationUsersOrganization,
),
) 2. Use a viewCreate a "Joined View" and define your relationship to the view. |
Beta Was this translation helpful? Give feedback.
The complexity of trying to
If I understand correctly what you're trying to do, you have a few options:
1. Have two separate relationships.
users
toorganization_user
organization_user
toorganizations
2. Use a view
Create a "Joined View" and define your relationship to the view.