Skip to content

Commit

Permalink
fixed table detection for []*T
Browse files Browse the repository at this point in the history
  • Loading branch information
ulfurinn committed Apr 29, 2014
1 parent 9d253d1 commit ca3f5ca
Show file tree
Hide file tree
Showing 2 changed files with 6 additions and 1 deletion.
6 changes: 5 additions & 1 deletion dbmap.go
Original file line number Diff line number Diff line change
Expand Up @@ -17,12 +17,13 @@ import (
"log"
"reflect"
"strings"

"github.com/jmoiron/sqlx"
)

// TableNameMapper is the function used by AddTable to map struct names to database table names, in analogy
// to sqlx.NameMapper which does the same for struct field name to database column names.
var TableNameMapper = strings.ToLower
var TableNameMapper = strings.ToLower

// DbMap is the root modl mapping object. Create one of these for each
// database schema you wish to map. Each DbMap contains a list of
Expand Down Expand Up @@ -375,6 +376,9 @@ start:
default:
t = v.Type()
}
if t.Kind() == reflect.Ptr {
t = t.Elem()
}
return m.TableForType(t)
}

Expand Down
1 change: 1 addition & 0 deletions modl_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -385,6 +385,7 @@ func TestHooks(t *testing.T) {
t.Errorf("p1.PostGet() didn't run: %v", p1)
}

p1.LName = "smith"
_update(dbmap, p1)
if p1.FName != "preupdate" {
t.Errorf("p1.PreUpdate() didn't run: %v", p1)
Expand Down

0 comments on commit ca3f5ca

Please sign in to comment.