Describe the feature

Ability to hide fields and relations at runtime

Motivation

  • I want to expose an array of users as an endpoint but hide the Password field
  • I want to expose an array of a users auth sessions as an endpoint but hide the User relation

Currently I found the way to hide my User relation to my Session model involved doing something like:

type Session struct {
    models.Session
    User *models.User `json:"User,omitempty"`
}

func Token(c *fiber.Ctx) error {
    user := auth.User(c)
    var sessions []Session
    database.Db.Find(&sessions, "user_id = ?", user.ID)
    return render.Render(c, sessions)
}

I'm not sure how it'd be possible (still new to go) but I'd love to see something like one of these:

database.Db.Find(&sessions, "user_id = ?", user.ID).HideRelation("User")
database.Db.Find(&sessions, "user_id = ?", user.ID).HideRelation(models.User)

database.Db.Find(&users, "id = ?", user.ID).HideField("Password")

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

Comment From: acidjazz

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

👀

Comment From: a631807682

Hide the results that do not belong to gorm.

https://pkg.go.dev/encoding/json