2016-08-28 12:48:50 +02:00
|
|
|
{{- if eq .NoHooks false -}}
|
2016-07-06 08:02:35 +02:00
|
|
|
{{- $tableNameSingular := .Table.Name | singular | titleCase -}}
|
|
|
|
{{- $tableNamePlural := .Table.Name | plural | titleCase -}}
|
|
|
|
{{- $varNamePlural := .Table.Name | plural | camelCase -}}
|
|
|
|
{{- $varNameSingular := .Table.Name | singular | camelCase -}}
|
2016-08-28 12:54:46 +02:00
|
|
|
func {{$varNameSingular}}BeforeInsertHook(o *{{$tableNameSingular}}) error {
|
2016-07-15 17:21:09 +02:00
|
|
|
*o = {{$tableNameSingular}}{}
|
2016-07-06 08:02:35 +02:00
|
|
|
return nil
|
|
|
|
}
|
|
|
|
|
2016-08-28 12:54:46 +02:00
|
|
|
func {{$varNameSingular}}AfterInsertHook(o *{{$tableNameSingular}}) error {
|
2016-07-15 17:21:09 +02:00
|
|
|
*o = {{$tableNameSingular}}{}
|
2016-07-06 08:02:35 +02:00
|
|
|
return nil
|
|
|
|
}
|
|
|
|
|
|
|
|
func {{$varNameSingular}}BeforeUpdateHook(o *{{$tableNameSingular}}) error {
|
2016-07-15 17:21:09 +02:00
|
|
|
*o = {{$tableNameSingular}}{}
|
2016-07-06 08:02:35 +02:00
|
|
|
return nil
|
|
|
|
}
|
|
|
|
|
|
|
|
func {{$varNameSingular}}AfterUpdateHook(o *{{$tableNameSingular}}) error {
|
2016-07-15 17:21:09 +02:00
|
|
|
*o = {{$tableNameSingular}}{}
|
2016-07-06 08:02:35 +02:00
|
|
|
return nil
|
|
|
|
}
|
|
|
|
|
2016-08-15 11:36:38 +02:00
|
|
|
func test{{$tableNamePlural}}Hooks(t *testing.T) {
|
|
|
|
t.Parallel()
|
|
|
|
|
2016-07-15 17:21:09 +02:00
|
|
|
var err error
|
2016-07-06 08:02:35 +02:00
|
|
|
|
2016-07-15 17:21:09 +02:00
|
|
|
empty := &{{$tableNameSingular}}{}
|
|
|
|
o := &{{$tableNameSingular}}{}
|
|
|
|
|
2016-08-18 09:06:28 +02:00
|
|
|
seed := randomize.NewSeed()
|
|
|
|
if err = randomize.Struct(seed, o, {{$varNameSingular}}DBTypes, false); err != nil {
|
2016-07-15 17:21:09 +02:00
|
|
|
t.Errorf("Unable to randomize {{$tableNameSingular}} object: %s", err)
|
|
|
|
}
|
|
|
|
|
2016-08-28 12:54:46 +02:00
|
|
|
{{$tableNameSingular}}AddHook(boil.HookBeforeInsert, {{$varNameSingular}}BeforeInsertHook)
|
|
|
|
if err = o.doBeforeInsertHooks(); err != nil {
|
|
|
|
t.Errorf("Unable to execute doBeforeInsertHooks: %s", err)
|
2016-07-15 17:21:09 +02:00
|
|
|
}
|
|
|
|
if !reflect.DeepEqual(o, empty) {
|
2016-08-28 12:54:46 +02:00
|
|
|
t.Errorf("Expected BeforeInsertHook function to empty object, but got: %#v", o)
|
2016-07-15 17:21:09 +02:00
|
|
|
}
|
|
|
|
|
2016-08-28 12:54:46 +02:00
|
|
|
{{$varNameSingular}}BeforeInsertHooks = []{{$tableNameSingular}}Hook{}
|
2016-07-06 08:02:35 +02:00
|
|
|
}
|
2016-08-28 12:48:50 +02:00
|
|
|
{{- end}}
|