Skip to content

Commit

Permalink
Merge pull request #10 from twharmon/to-get
Browse files Browse the repository at this point in the history
check query limit after model is set
  • Loading branch information
twharmon authored Feb 5, 2020
2 parents 2635d31 + 9684173 commit 99507b4
Showing 1 changed file with 6 additions and 3 deletions.
9 changes: 6 additions & 3 deletions select_query.go
Original file line number Diff line number Diff line change
Expand Up @@ -90,9 +90,6 @@ func (sq *SelectQuery) Get(out interface{}) error {
}
return sq.toOne(out)
case reflect.Slice:
if sq.limit == 0 {
return errors.New("limit must be set and not zero when selecting multiple rows")
}
el := t.Elem()
switch el.Kind() {
case reflect.Ptr:
Expand All @@ -104,12 +101,18 @@ func (sq *SelectQuery) Get(out interface{}) error {
if sq.model == nil {
return fmt.Errorf("you must first register %s", el.Name())
}
if sq.limit == 0 {
return errors.New("limit must be set and not zero when selecting multiple rows")
}
return sq.toMany(t, out)
case reflect.Struct:
sq.model = sq.db.models[el.Name()]
if sq.model == nil {
return fmt.Errorf("you must first register %s", el.Name())
}
if sq.limit == 0 {
return errors.New("limit must be set and not zero when selecting multiple rows")
}
return sq.toManyValues(t, out)
}
}
Expand Down

0 comments on commit 99507b4

Please sign in to comment.