Your Question
type Cat struct {
Id int
Name string
Toy Toy gorm:"polymorphic:Owner;"
}
type Dog struct {
Id int
Name string
Toys []Toy gorm:"polymorphic:Owner;"
}
type Toy struct { Id int Name string OwnerId int OwnerType string } any solution to find "Owner" of the particular Toy, instead of left join?
The document you expected this should be explained
https://gorm.io/docs/has_many.html
Others references:
https://stackoverflow.com/questions/65357752/how-should-i-reference-two-tables-with-a-single-foreign-key
https://sourcegraph.com/github.com/jinzhu/gorm/-/blob/polymorphic_test.go?L43
Expected answer
any solution to find "Owner" of the particular toy, instead of left joining dog and cat?
DB.Model(&toy).Related(&owner, "Owner")
DB.Model(&toy).Association("Owner")
Comment From: github-actions[bot]
This issue has been automatically marked as stale because it has been open 360 days with no activity. Remove stale label or comment or this will be closed in 180 days