This is based on the Belongs To relationship. Two structures are defined as:
type User struct {
gorm.Model
Profile Profile
ProfileID int
}
type Profile struct {
gorm.Model
Name string
}
The goal is to select all users that have a specified profile name. What I am looking for is an equivalent of this SQL statement:
select * from users
join profiles on users.profile_id = profiles.id
where profiles.name = 'foo'
I can obviously use explicit statements as join
or profile_id IN (?)
. Is there a good GORM way based on methods and models?