From d9ec68b76a634fd4eb3b2155f91618999f2c3c89 Mon Sep 17 00:00:00 2001 From: Patrick O'brien Date: Sun, 28 Aug 2016 22:02:21 +1000 Subject: [PATCH] Add afterSelectHooks to One and All finishers --- templates/03_finishers.tpl | 16 ++++++++++++++++ 1 file changed, 16 insertions(+) diff --git a/templates/03_finishers.tpl b/templates/03_finishers.tpl index 9c70e5e..b82f87a 100644 --- a/templates/03_finishers.tpl +++ b/templates/03_finishers.tpl @@ -24,6 +24,12 @@ func (q {{$varNameSingular}}Query) One() (*{{$tableNameSingular}}, error) { return nil, errors.Wrap(err, "{{.PkgName}}: failed to execute a one query for {{.Table.Name}}") } + {{if eq .NoHooks false -}} + if err := o.doAfterSelectHooks(); err != nil { + return o, err + } + {{- end}} + return o, nil } @@ -46,6 +52,16 @@ func (q {{$varNameSingular}}Query) All() ({{$tableNameSingular}}Slice, error) { return nil, errors.Wrap(err, "{{.PkgName}}: failed to assign all query results to {{$tableNameSingular}} slice") } + {{if eq .NoHooks false -}} + if len({{$varNameSingular}}AfterSelectHooks) != 0 { + for _, obj := range o { + if err := obj.doAfterSelectHooks(); err != nil { + return o, err + } + } + } + {{- end}} + return o, nil }