jinzhu/gorm — pull request #87 by nerdzeu (2014-04-06 02:09:05+00:00)
Title: Add support for primary key with name different from `id`

This can be useful for people that want to use gorm, but they already have an existing schema and they can't change table row names.

With these changes, is now possible to mark a field as primary key, and use the standard gorm methods that work with primary keys.

For example:
```go
type User struct {
Counter int64 `primaryKey:"yes"`
Last time.Time
NotifyStory string `sql:"type:json"`
Private bool
}
```

And I can work with gorm methods like:
```go
var user User

db.First(&user, 12)
```
And everything works fine.

Let me know what do you think about that.

Thank you!

(Now with a single commit pull request)
Below the list of previous commit, that explain the changes.

``history

Add getPrimaryKey: analize the tag string in the struct fields and find the one marked as primaryKey

Add primaryKey field to scope and uses getPrimaryKey to find the one marked in that way, if present. Otherwise fallback to id

Format code with gofmt

Fixes getPrimaryKey for non struct type

Add tests

add Tests for update a struct
```