Skip to content

Loading…

snakeCasedName for primary key #5

Closed
nexneo opened this Issue · 1 comment

2 participants

@nexneo

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

@astaxie
Owner

Issue #5

@astaxie astaxie added a commit that referenced this issue
@astaxie Issue #5
Issue #5
e3ea52d
@astaxie astaxie closed this
@astaxie astaxie added a commit that referenced this issue
@astaxie Primarykey error
snakeCasedName #5 #9 #10
18b889f
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.