Skip to content

Commit

Permalink
Merge branch 'renshaohai83/Sqlboiler_to_support_DDL_is_updated_smooth…
Browse files Browse the repository at this point in the history
…ly' into dev
  • Loading branch information
aarondl committed Nov 11, 2017
2 parents f5b3628 + 004c80c commit 6b95e5d
Show file tree
Hide file tree
Showing 2 changed files with 10 additions and 4 deletions.
8 changes: 6 additions & 2 deletions queries/reflect.go
Original file line number Diff line number Diff line change
Expand Up @@ -279,8 +279,8 @@ ColLoop:
continue ColLoop
}
}

return nil, errors.Errorf("could not find struct field name in mapping: %s", name)
// if c doesn't exist in the model, the pointer will be the zero value in the ptrs array and it's value will be thrown away
continue
}

return ptrs, nil
Expand Down Expand Up @@ -309,6 +309,10 @@ func ValuesFromMapping(val reflect.Value, mapping []uint64) []interface{} {
// ptrFromMapping expects to be passed an addressable struct that it's looking
// for things on.
func ptrFromMapping(val reflect.Value, mapping uint64, addressOf bool) reflect.Value {
if mapping == 0 {
var ignored interface{}
return reflect.ValueOf(&ignored)
}
for i := 0; i < 8; i++ {
v := (mapping >> uint(i*8)) & sentinel

Expand Down
6 changes: 4 additions & 2 deletions queries/reflect_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -283,8 +283,7 @@ func TestValuesFromMapping(t *testing.T) {
IntP: new(int),
},
}

mapping := []uint64{testMakeMapping(0), testMakeMapping(1), testMakeMapping(2, 0), testMakeMapping(2, 1)}
mapping := []uint64{testMakeMapping(0), testMakeMapping(1), testMakeMapping(2, 0), testMakeMapping(2, 1), 0}
v := ValuesFromMapping(reflect.Indirect(reflect.ValueOf(val)), mapping)

if got := v[0].(int); got != 5 {
Expand All @@ -299,6 +298,9 @@ func TestValuesFromMapping(t *testing.T) {
if got := v[3].(int); got != 0 {
t.Error("nested pointer was wrong:", got)
}
if got := *v[4].(*interface{}); got != nil {
t.Error("nil pointer was not be ignored:", got)
}
}

func TestPtrsFromMapping(t *testing.T) {
Expand Down

0 comments on commit 6b95e5d

Please sign in to comment.