Using Jinzhu's GORM Package which is fantastic btw, I currently have this struct:
type User struct {
gorm.Model
// The Users username
Username string `gorm:"size:255;unique;not null"`
// The Users email address
Email string `gorm:"size:255;unique;not null"`
// The Users hashed password
Password string `gorm:"size:255;not null"`
// The Users password confirmation (only for forms)
PasswordC string `gorm:"-"`
// The Users FULL NAME (e.g. Burt Reynolds)
Fullname string `gorm:"size:255; not null"`
// The Users Karma level
Karma int
// Is the user banned?
Banned bool
}
But I also use Gorilla's Schema
package so any form values populate the struct, but I don't want the PasswordC
to be saved into the database because it will be plain text as the normal Password
field gets bcrypt'd so any information on how to make GORM
not save the PasswordC
field.
The gorm docs indicate that's the correct syntax for ignoring a field: jinzhu.me/gorm/models.html#model-definition - are you seeing otherwise?
Tags are optional to use when declaring models, GORM supports the following tags: Tags are case insensitive, however camelCase is preferred.
DB. GORM provides the method DB which returns a generic database interface *sql.DB from the current *gorm.DB. // Get generic database object sql.DB to use its functions. sqlDB, err := db.DB()
The docs say gorm:"-"
, but the code indicates sql:"-"
is the correct syntax.
My testing verifies this.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With