snakeCasedName for primary key #5

nexneo opened this Issue Jul 28, 2012 · 1 comment


None yet
2 participants

nexneo commented Jul 28, 2012

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


This comment has been minimized.

Show comment
Hide comment

astaxie Aug 12, 2012


Issue #5


astaxie commented Aug 12, 2012

Issue #5

astaxie added a commit that referenced this issue Aug 12, 2012

Issue #5
Issue #5

@astaxie astaxie closed this Aug 12, 2012

astaxie added a commit that referenced this issue Aug 20, 2012

Primarykey error
snakeCasedName #5 #9 #10
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment