go-gorm / gorm

The fantastic ORM library for Golang, aims to be developer friendly
https://gorm.io
MIT License
36.48k stars 3.9k forks source link

How to omit a column on a joined struct? #5739

Open btomasini opened 1 year ago

btomasini commented 1 year ago

Your Question

How do I omit a column from a joined struct? I have the following:

type Client struct {
    Realm *Realm
    Config string  
}

type Realm struct {
   Config string
}

When I do the following clause:

db.Join("Realm").Omit("config", "Realm.config")

The config is omitted on the root client, but not the realm. How do I instruct Gorm to omit a column on a joined struct?

The document you expected this should be explained

https://gorm.io/docs/advanced_query.html

Expected answer

How to omit a column on a joined struct.

0fv commented 1 year ago

db.Omit("config").Joins("Realm",db.Omit("config"))