Reputation: 905
I have four nested models (simplified here):
type Client struct {
gorm.Model
UUID uuid.UUID `gorm:"type:uuid"`
Activity Activity
}
type Activity struct {
gorm.Model
ClientID uint
LoginActivities []LoginActivity
}
type LoginActivity struct {
gorm.Model
ActivityID uint
UUID uuid.UUID
Timestamp time.Time
Device DeviceInfo
}
type DeviceInfo struct {
gorm.Model
LoginActivityID uint
Platform string
}
And I want to retrieve all nested models with:
database.db.
Where("uuid = ?", clientID).
Preload("Activity.LoginActivities.DeviceInfos").
First(&client).
Error
However, I get the error DeviceInfos: unsupported relations for schema LoginActivity
Is the model wrongly set or the query wrong?
Upvotes: 0
Views: 3686
Reputation: 7742
You've used Preload("Activity.LoginActivities.DeviceInfos")
but the member that represents the relationship in LoginActivity
is Device
.
You should instead preload with Preload("Activity.LoginActivities.Device")
Upvotes: 3