Your Question
How gorm decide what preload entity to return from multiple options?
type Order struct {
gorm.Model
Status OrderStatus `gorm:"foreignKey:OrderID"`
}
type OrderStatus struct {
gorm.Model
OrderID uint
Status string `gorm:"column:status"`
}
once we get status update we want to save new status, keep old statuses in database
stateEntity := entity.OrderStatus{
Status: string(state.Status),
OrderID: orderID,
Details: entity.StatusDetails(state.Details),
}
err = s.db.
WithContext(ctx).
Clauses(clause.Returning{}).
Save(&stateEntity)
so in DB we have multiple statuses and gorm sometimes returns not latest added, but added before latest and consistently returns only it.
The document you expected this should be explained
(https://gorm.io/docs/preload.html)
Expected answer
Is there any docs describing how Preload decide what value should be returned in case of multiple options?
is there any better way to keep status updates and get only last added status with preload fucntion?