Hi there, right here is the code:
This consequence := db.Preload(“Person”).Discover(&articles) provides me the error “&{0xc0000fc2d0 Person: unsupported relations for schema Article 2 0xc0002f8540 0}”.
Are you able to assist me?
That is extra a Gorm query than a Go query. That mentioned, article doesn’t have a consumer related to it so Gorm doesn’t know how you can preload customers. You most likely wish to outline a relationship between these structs/tables:
On this case perhaps article has a consumer object because the creator. Additionally why do you might have a number of variations of consumer/article structs? Most likely finest to unify these.
Hi there Dean,
The code I gave incorporates 3 recordsdata. The service and the Person/Article fashions.
I’ve a overseas key in Articles and it really works advantageous. The issue comes when utilizing Preload.
You Article
struct doesn’t have a Person
struct as a property. Discuss with that hyperlink I posted for data on defining an affiliation in addition to this docs web page for preloading:
You’re attempting to db.Preload("Person")
however you don’t have a consumer object to preload in your Article
struct, therefore the error. You could outline the affiliation for it to work.