I am having an issue querying a many to many relationship... My relationships are as follows type User struct { ID string Roles []Role gorm:"many2many:user_roles;" }

type Role struct { ID string Users []User gorm:"many2many:user_roles;" RoleName string gorm:"not null" }

I have a table user_roles which has been created. When I create a user with a list of Role, those all get saved accordingly. What I am curious about is, how can I retrieve a list of users, based on a specific RoleName.

eg.

Select u.Id From users u Join user_roles ur on ur.user_id = u.id Join roles r on ur.role_id = r.id where r.role_name = 'xxxx'

I understand that GORM does it somewhat different. How would I accomplish essentially what this query returns?

https://gorm.io/docs/advanced_query.html OR https://gorm.io/docs/many_to_many.html

???

Comment From: doppl-neal

I believe I have figure this out...

Comment From: vavieira10

@doppl-neal How have you accomplished this? I've been facing the same issue