gorm: How to scan ignored field gorm:"-" ?

I have struct like this

type Menu struct {
	Name        string    `json:"name" gorm:"type:varchar(150);"`
	WebsiteName string    `json:"websiteName" gorm:"-"`
}

I want the WebsiteName to be able to scan but I do not want this field to be created in the Database. But when I add - the field does not get created in DB that’s good but when I Scan(&menu) the field is not getting scanned.

How do I make this work ?

About this issue

  • Original URL
  • State: closed
  • Created 2 years ago
  • Comments: 17 (4 by maintainers)

Most upvoted comments

@khanakia I haven’t tried, but I think it might help you

WebsiteName  string `gorm:"<-:false;->;-:migration"`

<-:false no write permission, -> read permission, and -:migration ignore migration. https://github.com/go-gorm/gorm/pull/4028