选择所有依赖项

Imagine the following model:

type (

    Account struct {
        gorm.Model

        CustomID string `gorm:"index;unique"`
        Name string
        Profiles []*Profiles `gorm:"ForeignKey:AccountID"`
    }

    Profile struct {
        gorm.Model

        AccountID uint `gorm:"index"`
        TheFoo *Foo
        TheDoo *Doo
    }

    Foo struct {
        ProfileID uint `gorm:"index"`
        Boo string
    }

    Doo struct {
        ProfileID uint `gorm:"index"`
        Moo string
    }
)

All my attempts of getting the entire structure always fails. acc is always filled with only the account data and no profiles.

I even expereimented with this db.Model(&acc).Related(&Profile{}) stuff but still no success. The (lets say, pretty bad) docs also do not clarify this.

var acc Account
db.Find(&acc, "custom_id = ?", myCustomID) 

how would you actually do this?

Can you add your code for when you call the related function? http://jinzhu.me/gorm/associations.html#has-many What Im seeing on the documentation for has-many it should look like this.

var acc Account
db.Find(&acc, "custom_id = ?", myCustomID)
db.Model(&acc).Related(&profiles)

I believe you can use the Preload method which supports ne, i.e.:

account := new(Account)
db.Preload("Profiles.TheDoo").Preload("Profiles.TheFoo").Find(account, "custom_id = ?", myCustomID)

I haven't checked yet if you actually need to preload Profiles as well, but it wouldn't hurt to use it if it turns out you do.