Skip to content

Commit

Permalink
Fix silently failing ListWhere() due to column mismatch
Browse files Browse the repository at this point in the history
Fixes Masterminds#13 by including columns that are marked as keys and returning
possible Scan errors.
  • Loading branch information
sgabe committed Aug 16, 2020
1 parent a1a302e commit 90e7c5a
Showing 1 changed file with 6 additions and 2 deletions.
8 changes: 6 additions & 2 deletions structable.go
Original file line number Diff line number Diff line change
Expand Up @@ -306,7 +306,7 @@ type WhereFunc func(desc Describer, query squirrel.SelectBuilder) (squirrel.Sele
// of each matches the underlying type of the passed-in 'd' Recorder.
func ListWhere(d Recorder, fn WhereFunc) ([]Recorder, error) {
var tn string = d.TableName()
var cols []string = d.Columns(false)
var cols []string = d.Columns(true)
buf := []Recorder{}

// Base query
Expand Down Expand Up @@ -338,7 +338,11 @@ func ListWhere(d Recorder, fn WhereFunc) ([]Recorder, error) {
s := nv.Interface().(Recorder)
s.Init(d.DB(), d.Driver())
dest := s.FieldReferences(true)
rows.Scan(dest...)

if err := rows.Scan(dest...); err != nil {
return buf, err
}

buf = append(buf, s)
}

Expand Down

0 comments on commit 90e7c5a

Please sign in to comment.