I have created this test script, the output shows that the content column gets created even if i define gorm:"-":
package main
import (
"fmt"
"github.com/jinzhu/gorm"
_ "github.com/jinzhu/gorm/dialects/sqlite"
)
type Foo struct {
gorm.Model
Content string `json:"content" gorm:"-"`
}
func main() {
db, err := gorm.Open("sqlite3", "database.sqlite3")
if err != nil {
panic(err)
}
db.LogMode(true)
db.AutoMigrate(&Foo{})
foo1 := &Foo{Content: ""}
db.Create(foo1)
check := &Foo{}
db.Last(check)
fmt.Println(check.Content)
}
The output:
# go run main.go
(/home/tboerger/Projects/golang/src/github.com/foo/foo/main.go:23)
[2016-03-16 16:09:33] [2.82ms] CREATE TABLE "foos" ("id" integer primary key autoincrement,"created_at" datetime,"updated_at" datetime,"deleted_at" datetime,"content" varchar(255) )
(/home/tboerger/Projects/golang/src/github.com/foo/foo/main.go:23)
[2016-03-16 16:09:33] [5.44ms] CREATE INDEX idx_foos_deleted_at ON "foos"("deleted_at")
(/home/tboerger/Projects/golang/src/github.com/foo/foo/main.go:26)
[2016-03-16 16:09:33] [0.31ms] INSERT INTO "foos" ("created_at","updated_at","deleted_at","content") VALUES ('2016-03-16T16:09:33+01:00','2016-03-16T16:09:33+01:00','<nil>','')
(/home/tboerger/Projects/golang/src/github.com/foo/foo/main.go:29)
[2016-03-16 16:09:33] [0.30ms] SELECT * FROM "foos" WHERE "foos".deleted_at IS NULL ORDER BY "foos"."id" DESC LIMIT 1
Hi,
FYI, my current workaround is to replace gorm:"-" by sql:"-".
FYI, my current workaround is to replace gorm:"-" by sql:"-".
Thanks for the hint, but to avoid confusion this bug should be fixed or the docs should be updated.
I suppose you are using an old GORM version
Hi, i have the same issue, but sql:"-" (instead of gorm:"-") doesn't work for me. I am using latest version of gorm.
This should been fixed, sorry for this.
Most helpful comment
This should been fixed, sorry for this.