Skip to content


snakeCasedName for primary key #5

nexneo opened this Issue · 1 comment

2 participants


By convention Model struct field names maps to db names via snakeCasedName method but primary key doesn't follow that pattern in Save and Insert .

I have just started with Golang so mostly it could be my mistake but...

In func (orm *Model) Save(output interface{}) error

    id := results[strings.ToLower(orm.PrimaryKey)]
    delete(results, strings.ToLower(orm.PrimaryKey))

it should be using snakeCasedName instead directly using toLower

In func (orm *Model) Insert(properties map[string]interface{}) (int64, error)

    if orm.ParamIdentifier == "pg" {
        statement = fmt.Sprintf("%v RETURNING %v", statement, orm.PrimaryKey)
        var id int64
        orm.Db.QueryRow(statement, args...).Scan(&id)
        return id, nil

here no conversion applied to PrimaryKey so it does not insert without setting PrimaryKey via SetPK


Issue #5

@astaxie astaxie added a commit that referenced this issue
@astaxie Issue #5
Issue #5
@astaxie astaxie closed this
@astaxie astaxie added a commit that referenced this issue
@astaxie Primarykey error
snakeCasedName #5 #9 #10
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Something went wrong with that request. Please try again.