Gorm: custom Model struct doesn't populate ID properly

Created on 14 Jun 2018  路  5Comments  路  Source: go-gorm/gorm

What version of Go are you using (go version)?

1.10

Which database and its version are you using?

Postgres 9.4

Please provide a complete runnable program to reproduce your issue. IMPORTANT

Will provide soon. Basically, if I have

type model struct {
  ID uuid.UUID
}

type Person struct {
  model
  Name string
  Age int
}

func main() {
  ...
  p := Person{"Bob", 34}
  db.Create(&p)
  fmt.Println(p.ID)
}

the ID doesn't get set.

Most helpful comment

@ags799 maybe you should use type Model struct instead of type model struct so that gorm can access the p.ID.

All 5 comments

I'm going to piggyback on this with a more complete example and a trace at my created issue #1952

I have created a repo as an example of this bug: https://github.com/ags799/gorm-1950

The ticket #1887 seems to be related, but using postgresql. They seem to have a working version with a postgres specific UUID extension.

@ags799 maybe you should use type Model struct instead of type model struct so that gorm can access the p.ID.

@zxdvd thanks this works

Was this page helpful?
0 / 5 - 0 ratings

Related issues

pjebs picture pjebs  路  3Comments

koalacxr picture koalacxr  路  3Comments

bramp picture bramp  路  3Comments

littletwolee picture littletwolee  路  3Comments

satb picture satb  路  3Comments