I recently started using Golang and decided to give GORM a try as an ORM. It works pretty well on most things, but as most ORMs are sometimes it's limited. Luckily it ties very well into database/sql so I can do custom queries easily.
I'm wondering if there is any other way to do this in gorm: I have a struct Companies, Companies have one to many relationships w/ emails, addresses, and phones. I use the following code in gorm to pull a list of companies and their corresponding info. I use gorm's Preload function.
db.DBAccess.
Model(&companies).
Count(&dbInfo.Count).
Order("companies.id asc").
Offset(offset).
Limit(length).
Preload("Addresses").
Preload("Phones").
Preload("Emails").
Find(&companies)
This works perfectly fine. However I feel like there is another way to accomplish this without the Preload function. Any ideas?
Preload
so long as the relation is specified correctly. If not some option should be added to the package likeCascadingRead
that causes a recursive instantiation rather than returning me an object with empty arrays that should hold the many items my current object has foreign key relations with. – evanmcdonnal