From d1268b9f8f9abf99bd1a1d5f25ace3763fb49423 Mon Sep 17 00:00:00 2001 From: Travis Harmon Date: Tue, 4 Feb 2020 19:42:33 -0500 Subject: [PATCH] check query limit after model is set --- select_query.go | 9 ++++++--- 1 file changed, 6 insertions(+), 3 deletions(-) diff --git a/select_query.go b/select_query.go index aa096a9..c9ba4bc 100644 --- a/select_query.go +++ b/select_query.go @@ -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: @@ -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) } }