2016-05-01 90 views
4

使用金珠的GORM包装这太棒了顺便说一句,我现在有这样的结构:GORM没有忽视场`GORM:“ - ”'

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 
} 

但我也用大猩猩的Schema包,因此任何形式的值填充结构,但我不希望PasswordC保存到数据库中,因为它将是纯文本的,因为正常的Password字段被加密,因此有关如何使GORM不保存PasswordC字段的任何信息。

+0

gorm docs表明这是忽略字段的正确语法:http://jinzhu.me/gorm/models.html#model-definition--你看到了吗? – elithrar

+1

尝试通过替换它,PasswordC字符串'sql:“ - ”' – qwertmax

回答

8

docsgorm:"-",但code表示sql:"-"是正确的语法。

我的测试验证了这一点。

+4

这不再正确。 [code](https://github.com/jinzhu/gorm/commit/465f8ea05b5638e508d29985eed6615402a9c2eb)已被修复。 –

+1

gorm:“ - ”不适合我? –