diff --git a/templates.go b/templates.go index c0a3573..3c8fb91 100644 --- a/templates.go +++ b/templates.go @@ -106,8 +106,9 @@ var templateStringMappers = map[string]func(string) string{ var templateFunctions = template.FuncMap{ // String ops "substring": strmangle.Substring, - "remove": func(rem string, str string) string { return strings.Replace(str, rem, "", -1) }, - "prefix": func(add string, str string) string { return fmt.Sprintf("%s%s", add, str) }, + "remove": func(rem, str string) string { return strings.Replace(str, rem, "", -1) }, + "replace": func(rep, with, str string) string { return strings.Replace(str, rep, with, -1) }, + "prefix": func(add, str string) string { return fmt.Sprintf("%s%s", add, str) }, "quoteWrap": func(a string) string { return fmt.Sprintf(`"%s"`, a) }, // Pluralization @@ -138,4 +139,5 @@ var templateFunctions = template.FuncMap{ "sqlColDefinitions": bdb.SQLColDefinitions, "sqlColDefStrings": bdb.SQLColDefStrings, "columnNames": bdb.ColumnNames, + "toManyRelationships": bdb.ToManyRelationships, } diff --git a/templates/04_relationship_to_one.tpl b/templates/04_relationship_to_one.tpl index 8e83079..5c39e21 100644 --- a/templates/04_relationship_to_one.tpl +++ b/templates/04_relationship_to_one.tpl @@ -12,7 +12,7 @@ func ({{$receiver}} *{{$localTable}}) {{$foreignColumn}}(exec boil.Executor, selectCols ...string) (*{{$foreignTable}}, error) { {{$varname}} := &{{$foreignTable}}{} - query := fmt.Sprintf(`select %s from {{.ForeignTable}} where id = $1`, strings.Join(selectCols, `,`)) + query := fmt.Sprintf(`select "%s" from {{.ForeignTable}} where id = $1`, strings.Join(selectCols, `","`)) err := exec.QueryRow(query, {{$receiver}}.{{titleCase .Column}}).Scan(boil.GetStructPointers({{$varname}}, selectCols...)...) if err != nil { return nil, fmt.Errorf(`{{$pkg}}: unable to select from {{.ForeignTable}}: %v`, err)