Fix receiver lint errs

This commit is contained in:
Patrick O'brien 2016-09-21 13:37:28 +10:00
parent f48b041daa
commit 522cb6824c
8 changed files with 84 additions and 93 deletions

View file

@ -5,14 +5,14 @@
{{- $txt := txtsFromFKey $dot.Tables $dot.Table . -}} {{- $txt := txtsFromFKey $dot.Tables $dot.Table . -}}
{{- $varNameSingular := .ForeignTable | singular | camelCase -}} {{- $varNameSingular := .ForeignTable | singular | camelCase -}}
// {{$txt.Function.Name}}G pointed to by the foreign key. // {{$txt.Function.Name}}G pointed to by the foreign key.
func ({{$txt.Function.Receiver}} *{{$txt.LocalTable.NameGo}}) {{$txt.Function.Name}}G(mods ...qm.QueryMod) {{$varNameSingular}}Query { func (o *{{$txt.LocalTable.NameGo}}) {{$txt.Function.Name}}G(mods ...qm.QueryMod) {{$varNameSingular}}Query {
return {{$txt.Function.Receiver}}.{{$txt.Function.Name}}(boil.GetDB(), mods...) return o.{{$txt.Function.Name}}(boil.GetDB(), mods...)
} }
// {{$txt.Function.Name}} pointed to by the foreign key. // {{$txt.Function.Name}} pointed to by the foreign key.
func ({{$txt.Function.Receiver}} *{{$txt.LocalTable.NameGo}}) {{$txt.Function.Name}}(exec boil.Executor, mods ...qm.QueryMod) ({{$varNameSingular}}Query) { func (o *{{$txt.LocalTable.NameGo}}) {{$txt.Function.Name}}(exec boil.Executor, mods ...qm.QueryMod) ({{$varNameSingular}}Query) {
queryMods := []qm.QueryMod{ queryMods := []qm.QueryMod{
qm.Where("{{$txt.ForeignTable.ColumnName}}={{if $dot.Dialect.IndexPlaceholders}}$1{{else}}?{{end}}", {{$txt.Function.Receiver}}.{{$txt.LocalTable.ColumnNameGo}}), qm.Where("{{$txt.ForeignTable.ColumnName}}={{if $dot.Dialect.IndexPlaceholders}}$1{{else}}?{{end}}", o.{{$txt.LocalTable.ColumnNameGo}}),
} }
queryMods = append(queryMods, mods...) queryMods = append(queryMods, mods...)

View file

@ -5,14 +5,14 @@
{{- $txt := txtsFromOneToOne $dot.Tables $dot.Table . -}} {{- $txt := txtsFromOneToOne $dot.Tables $dot.Table . -}}
{{- $varNameSingular := .ForeignTable | singular | camelCase -}} {{- $varNameSingular := .ForeignTable | singular | camelCase -}}
// {{$txt.Function.Name}}G pointed to by the foreign key. // {{$txt.Function.Name}}G pointed to by the foreign key.
func ({{$txt.Function.Receiver}} *{{$txt.LocalTable.NameGo}}) {{$txt.Function.Name}}G(mods ...qm.QueryMod) {{$varNameSingular}}Query { func (o *{{$txt.LocalTable.NameGo}}) {{$txt.Function.Name}}G(mods ...qm.QueryMod) {{$varNameSingular}}Query {
return {{$txt.Function.Receiver}}.{{$txt.Function.Name}}(boil.GetDB(), mods...) return o.{{$txt.Function.Name}}(boil.GetDB(), mods...)
} }
// {{$txt.Function.Name}} pointed to by the foreign key. // {{$txt.Function.Name}} pointed to by the foreign key.
func ({{$txt.Function.Receiver}} *{{$txt.LocalTable.NameGo}}) {{$txt.Function.Name}}(exec boil.Executor, mods ...qm.QueryMod) ({{$varNameSingular}}Query) { func (o *{{$txt.LocalTable.NameGo}}) {{$txt.Function.Name}}(exec boil.Executor, mods ...qm.QueryMod) ({{$varNameSingular}}Query) {
queryMods := []qm.QueryMod{ queryMods := []qm.QueryMod{
qm.Where("{{$txt.ForeignTable.ColumnName}}={{if $dot.Dialect.IndexPlaceholders}}$1{{else}}?{{end}}", {{$txt.Function.Receiver}}.{{$txt.LocalTable.ColumnNameGo}}), qm.Where("{{$txt.ForeignTable.ColumnName}}={{if $dot.Dialect.IndexPlaceholders}}$1{{else}}?{{end}}", o.{{$txt.LocalTable.ColumnNameGo}}),
} }
queryMods = append(queryMods, mods...) queryMods = append(queryMods, mods...)

View file

@ -8,13 +8,13 @@
{{- $schemaForeignTable := .ForeignTable | $dot.SchemaTable -}} {{- $schemaForeignTable := .ForeignTable | $dot.SchemaTable -}}
// {{$rel.Function.Name}}G retrieves all the {{$rel.LocalTable.NameSingular}}'s {{$rel.ForeignTable.NameHumanReadable}} // {{$rel.Function.Name}}G retrieves all the {{$rel.LocalTable.NameSingular}}'s {{$rel.ForeignTable.NameHumanReadable}}
{{- if not (eq $rel.Function.Name $rel.ForeignTable.NamePluralGo)}} via {{.ForeignColumn}} column{{- end}}. {{- if not (eq $rel.Function.Name $rel.ForeignTable.NamePluralGo)}} via {{.ForeignColumn}} column{{- end}}.
func ({{$rel.Function.Receiver}} *{{$rel.LocalTable.NameGo}}) {{$rel.Function.Name}}G(mods ...qm.QueryMod) {{$varNameSingular}}Query { func (o *{{$rel.LocalTable.NameGo}}) {{$rel.Function.Name}}G(mods ...qm.QueryMod) {{$varNameSingular}}Query {
return {{$rel.Function.Receiver}}.{{$rel.Function.Name}}(boil.GetDB(), mods...) return o.{{$rel.Function.Name}}(boil.GetDB(), mods...)
} }
// {{$rel.Function.Name}} retrieves all the {{$rel.LocalTable.NameSingular}}'s {{$rel.ForeignTable.NameHumanReadable}} with an executor // {{$rel.Function.Name}} retrieves all the {{$rel.LocalTable.NameSingular}}'s {{$rel.ForeignTable.NameHumanReadable}} with an executor
{{- if not (eq $rel.Function.Name $rel.ForeignTable.NamePluralGo)}} via {{.ForeignColumn}} column{{- end}}. {{- if not (eq $rel.Function.Name $rel.ForeignTable.NamePluralGo)}} via {{.ForeignColumn}} column{{- end}}.
func ({{$rel.Function.Receiver}} *{{$rel.LocalTable.NameGo}}) {{$rel.Function.Name}}(exec boil.Executor, mods ...qm.QueryMod) {{$varNameSingular}}Query { func (o *{{$rel.LocalTable.NameGo}}) {{$rel.Function.Name}}(exec boil.Executor, mods ...qm.QueryMod) {{$varNameSingular}}Query {
queryMods := []qm.QueryMod{ queryMods := []qm.QueryMod{
qm.Select("{{id 0 | $dot.Quotes}}.*"), qm.Select("{{id 0 | $dot.Quotes}}.*"),
} }
@ -26,11 +26,11 @@ func ({{$rel.Function.Receiver}} *{{$rel.LocalTable.NameGo}}) {{$rel.Function.Na
{{if .ToJoinTable -}} {{if .ToJoinTable -}}
queryMods = append(queryMods, queryMods = append(queryMods,
qm.InnerJoin("{{.JoinTable | $dot.SchemaTable}} as {{id 1 | $dot.Quotes}} on {{id 0 | $dot.Quotes}}.{{.ForeignColumn | $dot.Quotes}} = {{id 1 | $dot.Quotes}}.{{.JoinForeignColumn | $dot.Quotes}}"), qm.InnerJoin("{{.JoinTable | $dot.SchemaTable}} as {{id 1 | $dot.Quotes}} on {{id 0 | $dot.Quotes}}.{{.ForeignColumn | $dot.Quotes}} = {{id 1 | $dot.Quotes}}.{{.JoinForeignColumn | $dot.Quotes}}"),
qm.Where("{{id 1 | $dot.Quotes}}.{{.JoinLocalColumn | $dot.Quotes}}={{if $dot.Dialect.IndexPlaceholders}}$1{{else}}?{{end}}", {{$rel.Function.Receiver}}.{{$rel.LocalTable.ColumnNameGo}}), qm.Where("{{id 1 | $dot.Quotes}}.{{.JoinLocalColumn | $dot.Quotes}}={{if $dot.Dialect.IndexPlaceholders}}$1{{else}}?{{end}}", o.{{$rel.LocalTable.ColumnNameGo}}),
) )
{{else -}} {{else -}}
queryMods = append(queryMods, queryMods = append(queryMods,
qm.Where("{{id 0 | $dot.Quotes}}.{{.ForeignColumn | $dot.Quotes}}={{if $dot.Dialect.IndexPlaceholders}}$1{{else}}?{{end}}", {{$rel.Function.Receiver}}.{{$rel.LocalTable.ColumnNameGo}}), qm.Where("{{id 0 | $dot.Quotes}}.{{.ForeignColumn | $dot.Quotes}}={{if $dot.Dialect.IndexPlaceholders}}$1{{else}}?{{end}}", o.{{$rel.LocalTable.ColumnNameGo}}),
) )
{{end}} {{end}}

View file

@ -7,9 +7,9 @@
{{- $varNameSingular := .ForeignTable | singular | camelCase -}} {{- $varNameSingular := .ForeignTable | singular | camelCase -}}
{{- $localNameSingular := .Table | singular | camelCase}} {{- $localNameSingular := .Table | singular | camelCase}}
// Set{{$txt.Function.Name}} of the {{.Table | singular}} to the related item. // Set{{$txt.Function.Name}} of the {{.Table | singular}} to the related item.
// Sets {{$txt.Function.Receiver}}.R.{{$txt.Function.Name}} to related. // Sets o.R.{{$txt.Function.Name}} to related.
// Adds {{$txt.Function.Receiver}} to related.R.{{$txt.Function.ForeignName}}. // Adds o to related.R.{{$txt.Function.ForeignName}}.
func ({{$txt.Function.Receiver}} *{{$txt.LocalTable.NameGo}}) Set{{$txt.Function.Name}}(exec boil.Executor, insert bool, related *{{$txt.ForeignTable.NameGo}}) error { func (o *{{$txt.LocalTable.NameGo}}) Set{{$txt.Function.Name}}(exec boil.Executor, insert bool, related *{{$txt.ForeignTable.NameGo}}) error {
var err error var err error
if insert { if insert {
if err = related.Insert(exec); err != nil { if err = related.Insert(exec); err != nil {
@ -17,42 +17,42 @@ func ({{$txt.Function.Receiver}} *{{$txt.LocalTable.NameGo}}) Set{{$txt.Function
} }
} }
oldVal := {{$txt.Function.Receiver}}.{{$txt.Function.LocalAssignment}} oldVal := o.{{$txt.Function.LocalAssignment}}
{{$txt.Function.Receiver}}.{{$txt.Function.LocalAssignment}} = related.{{$txt.Function.ForeignAssignment}} o.{{$txt.Function.LocalAssignment}} = related.{{$txt.Function.ForeignAssignment}}
{{if .Nullable -}} {{if .Nullable -}}
{{$txt.Function.Receiver}}.{{$txt.LocalTable.ColumnNameGo}}.Valid = true o.{{$txt.LocalTable.ColumnNameGo}}.Valid = true
{{- end}} {{- end}}
if err = {{$txt.Function.Receiver}}.Update(exec, "{{.Column}}"); err != nil { if err = o.Update(exec, "{{.Column}}"); err != nil {
{{$txt.Function.Receiver}}.{{$txt.Function.LocalAssignment}} = oldVal o.{{$txt.Function.LocalAssignment}} = oldVal
{{if .Nullable -}} {{if .Nullable -}}
{{$txt.Function.Receiver}}.{{$txt.LocalTable.ColumnNameGo}}.Valid = false o.{{$txt.LocalTable.ColumnNameGo}}.Valid = false
{{- end}} {{- end}}
return errors.Wrap(err, "failed to update local table") return errors.Wrap(err, "failed to update local table")
} }
if {{$txt.Function.Receiver}}.R == nil { if o.R == nil {
{{$txt.Function.Receiver}}.R = &{{$localNameSingular}}R{ o.R = &{{$localNameSingular}}R{
{{$txt.Function.Name}}: related, {{$txt.Function.Name}}: related,
} }
} else { } else {
{{$txt.Function.Receiver}}.R.{{$txt.Function.Name}} = related o.R.{{$txt.Function.Name}} = related
} }
{{if .Unique -}} {{if .Unique -}}
if related.R == nil { if related.R == nil {
related.R = &{{$varNameSingular}}R{ related.R = &{{$varNameSingular}}R{
{{$txt.Function.ForeignName}}: {{$txt.Function.Receiver}}, {{$txt.Function.ForeignName}}: o,
} }
} else { } else {
related.R.{{$txt.Function.ForeignName}} = {{$txt.Function.Receiver}} related.R.{{$txt.Function.ForeignName}} = o
} }
{{else -}} {{else -}}
if related.R == nil { if related.R == nil {
related.R = &{{$varNameSingular}}R{ related.R = &{{$varNameSingular}}R{
{{$txt.Function.ForeignName}}: {{$txt.LocalTable.NameGo}}Slice{{"{"}}{{$txt.Function.Receiver}}{{"}"}}, {{$txt.Function.ForeignName}}: {{$txt.LocalTable.NameGo}}Slice{{"{"}}o{{"}"}},
} }
} else { } else {
related.R.{{$txt.Function.ForeignName}} = append(related.R.{{$txt.Function.ForeignName}}, {{$txt.Function.Receiver}}) related.R.{{$txt.Function.ForeignName}} = append(related.R.{{$txt.Function.ForeignName}}, o)
} }
{{- end}} {{- end}}
@ -61,18 +61,18 @@ func ({{$txt.Function.Receiver}} *{{$txt.LocalTable.NameGo}}) Set{{$txt.Function
{{- if .Nullable}} {{- if .Nullable}}
// Remove{{$txt.Function.Name}} relationship. // Remove{{$txt.Function.Name}} relationship.
// Sets {{$txt.Function.Receiver}}.R.{{$txt.Function.Name}} to nil. // Sets o.R.{{$txt.Function.Name}} to nil.
// Removes {{$txt.Function.Receiver}} from all passed in related items' relationships struct (Optional). // Removes o from all passed in related items' relationships struct (Optional).
func ({{$txt.Function.Receiver}} *{{$txt.LocalTable.NameGo}}) Remove{{$txt.Function.Name}}(exec boil.Executor, related *{{$txt.ForeignTable.NameGo}}) error { func (o *{{$txt.LocalTable.NameGo}}) Remove{{$txt.Function.Name}}(exec boil.Executor, related *{{$txt.ForeignTable.NameGo}}) error {
var err error var err error
{{$txt.Function.Receiver}}.{{$txt.LocalTable.ColumnNameGo}}.Valid = false o.{{$txt.LocalTable.ColumnNameGo}}.Valid = false
if err = {{$txt.Function.Receiver}}.Update(exec, "{{.Column}}"); err != nil { if err = o.Update(exec, "{{.Column}}"); err != nil {
{{$txt.Function.Receiver}}.{{$txt.LocalTable.ColumnNameGo}}.Valid = true o.{{$txt.LocalTable.ColumnNameGo}}.Valid = true
return errors.Wrap(err, "failed to update local table") return errors.Wrap(err, "failed to update local table")
} }
{{$txt.Function.Receiver}}.R.{{$txt.Function.Name}} = nil o.R.{{$txt.Function.Name}} = nil
if related == nil || related.R == nil { if related == nil || related.R == nil {
return nil return nil
} }
@ -82,9 +82,9 @@ func ({{$txt.Function.Receiver}} *{{$txt.LocalTable.NameGo}}) Remove{{$txt.Funct
{{else -}} {{else -}}
for i, ri := range related.R.{{$txt.Function.ForeignName}} { for i, ri := range related.R.{{$txt.Function.ForeignName}} {
{{if $txt.Function.UsesBytes -}} {{if $txt.Function.UsesBytes -}}
if 0 != bytes.Compare({{$txt.Function.Receiver}}.{{$txt.Function.LocalAssignment}}, ri.{{$txt.Function.LocalAssignment}}) { if 0 != bytes.Compare(o.{{$txt.Function.LocalAssignment}}, ri.{{$txt.Function.LocalAssignment}}) {
{{else -}} {{else -}}
if {{$txt.Function.Receiver}}.{{$txt.Function.LocalAssignment}} != ri.{{$txt.Function.LocalAssignment}} { if o.{{$txt.Function.LocalAssignment}} != ri.{{$txt.Function.LocalAssignment}} {
{{end -}} {{end -}}
continue continue
} }

View file

@ -6,13 +6,13 @@
{{- $varNameSingular := .ForeignTable | singular | camelCase -}} {{- $varNameSingular := .ForeignTable | singular | camelCase -}}
{{- $localNameSingular := .Table | singular | camelCase}} {{- $localNameSingular := .Table | singular | camelCase}}
// Set{{$txt.Function.Name}} of the {{.Table | singular}} to the related item. // Set{{$txt.Function.Name}} of the {{.Table | singular}} to the related item.
// Sets {{$txt.Function.Receiver}}.R.{{$txt.Function.Name}} to related. // Sets o.R.{{$txt.Function.Name}} to related.
// Adds {{$txt.Function.Receiver}} to related.R.{{$txt.Function.ForeignName}}. // Adds o to related.R.{{$txt.Function.ForeignName}}.
func ({{$txt.Function.Receiver}} *{{$txt.LocalTable.NameGo}}) Set{{$txt.Function.Name}}(exec boil.Executor, insert bool, related *{{$txt.ForeignTable.NameGo}}) error { func (o *{{$txt.LocalTable.NameGo}}) Set{{$txt.Function.Name}}(exec boil.Executor, insert bool, related *{{$txt.ForeignTable.NameGo}}) error {
var err error var err error
oldVal := related.{{$txt.Function.ForeignAssignment}} oldVal := related.{{$txt.Function.ForeignAssignment}}
related.{{$txt.Function.ForeignAssignment}} = {{$txt.Function.Receiver}}.{{$txt.Function.LocalAssignment}} related.{{$txt.Function.ForeignAssignment}} = o.{{$txt.Function.LocalAssignment}}
{{if .ForeignColumnNullable -}} {{if .ForeignColumnNullable -}}
related.{{$txt.ForeignTable.ColumnNameGo}}.Valid = true related.{{$txt.ForeignTable.ColumnNameGo}}.Valid = true
{{- end}} {{- end}}
@ -35,29 +35,29 @@ func ({{$txt.Function.Receiver}} *{{$txt.LocalTable.NameGo}}) Set{{$txt.Function
} }
} }
if {{$txt.Function.Receiver}}.R == nil { if o.R == nil {
{{$txt.Function.Receiver}}.R = &{{$localNameSingular}}R{ o.R = &{{$localNameSingular}}R{
{{$txt.Function.Name}}: related, {{$txt.Function.Name}}: related,
} }
} else { } else {
{{$txt.Function.Receiver}}.R.{{$txt.Function.Name}} = related o.R.{{$txt.Function.Name}} = related
} }
if related.R == nil { if related.R == nil {
related.R = &{{$varNameSingular}}R{ related.R = &{{$varNameSingular}}R{
{{$txt.Function.ForeignName}}: {{$txt.Function.Receiver}}, {{$txt.Function.ForeignName}}: o,
} }
} else { } else {
related.R.{{$txt.Function.ForeignName}} = {{$txt.Function.Receiver}} related.R.{{$txt.Function.ForeignName}} = o
} }
return nil return nil
} }
{{- if .ForeignColumnNullable}} {{- if .ForeignColumnNullable}}
// Remove{{$txt.Function.Name}} relationship. // Remove{{$txt.Function.Name}} relationship.
// Sets {{$txt.Function.Receiver}}.R.{{$txt.Function.Name}} to nil. // Sets o.R.{{$txt.Function.Name}} to nil.
// Removes {{$txt.Function.Receiver}} from all passed in related items' relationships struct (Optional). // Removes o from all passed in related items' relationships struct (Optional).
func ({{$txt.Function.Receiver}} *{{$txt.LocalTable.NameGo}}) Remove{{$txt.Function.Name}}(exec boil.Executor, related *{{$txt.ForeignTable.NameGo}}) error { func (o *{{$txt.LocalTable.NameGo}}) Remove{{$txt.Function.Name}}(exec boil.Executor, related *{{$txt.ForeignTable.NameGo}}) error {
var err error var err error
related.{{$txt.ForeignTable.ColumnNameGo}}.Valid = false related.{{$txt.ForeignTable.ColumnNameGo}}.Valid = false
@ -66,7 +66,7 @@ func ({{$txt.Function.Receiver}} *{{$txt.LocalTable.NameGo}}) Remove{{$txt.Funct
return errors.Wrap(err, "failed to update local table") return errors.Wrap(err, "failed to update local table")
} }
{{$txt.Function.Receiver}}.R.{{$txt.Function.Name}} = nil o.R.{{$txt.Function.Name}} = nil
if related == nil || related.R == nil { if related == nil || related.R == nil {
return nil return nil
} }

View file

@ -10,13 +10,13 @@
{{- $foreignNameSingular := .ForeignTable | singular | camelCase}} {{- $foreignNameSingular := .ForeignTable | singular | camelCase}}
// Add{{$rel.Function.Name}} adds the given related objects to the existing relationships // Add{{$rel.Function.Name}} adds the given related objects to the existing relationships
// of the {{$table.Name | singular}}, optionally inserting them as new records. // of the {{$table.Name | singular}}, optionally inserting them as new records.
// Appends related to {{$rel.Function.Receiver}}.R.{{$rel.Function.Name}}. // Appends related to o.R.{{$rel.Function.Name}}.
// Sets related.R.{{$rel.Function.ForeignName}} appropriately. // Sets related.R.{{$rel.Function.ForeignName}} appropriately.
func ({{$rel.Function.Receiver}} *{{$rel.LocalTable.NameGo}}) Add{{$rel.Function.Name}}(exec boil.Executor, insert bool, related ...*{{$rel.ForeignTable.NameGo}}) error { func (o *{{$rel.LocalTable.NameGo}}) Add{{$rel.Function.Name}}(exec boil.Executor, insert bool, related ...*{{$rel.ForeignTable.NameGo}}) error {
var err error var err error
for _, rel := range related { for _, rel := range related {
{{if not .ToJoinTable -}} {{if not .ToJoinTable -}}
rel.{{$rel.Function.ForeignAssignment}} = {{$rel.Function.Receiver}}.{{$rel.Function.LocalAssignment}} rel.{{$rel.Function.ForeignAssignment}} = o.{{$rel.Function.LocalAssignment}}
{{if .ForeignColumnNullable -}} {{if .ForeignColumnNullable -}}
rel.{{$rel.ForeignTable.ColumnNameGo}}.Valid = true rel.{{$rel.ForeignTable.ColumnNameGo}}.Valid = true
{{end -}} {{end -}}
@ -35,7 +35,7 @@ func ({{$rel.Function.Receiver}} *{{$rel.LocalTable.NameGo}}) Add{{$rel.Function
{{if .ToJoinTable -}} {{if .ToJoinTable -}}
for _, rel := range related { for _, rel := range related {
query := "insert into {{.JoinTable | $dot.SchemaTable}} ({{.JoinLocalColumn | $dot.Quotes}}, {{.JoinForeignColumn | $dot.Quotes}}) values {{if $dot.Dialect.IndexPlaceholders}}($1, $2){{else}}(?, ?){{end}}" query := "insert into {{.JoinTable | $dot.SchemaTable}} ({{.JoinLocalColumn | $dot.Quotes}}, {{.JoinForeignColumn | $dot.Quotes}}) values {{if $dot.Dialect.IndexPlaceholders}}($1, $2){{else}}(?, ?){{end}}"
values := []interface{}{{"{"}}{{$rel.Function.Receiver}}.{{$rel.LocalTable.ColumnNameGo}}, rel.{{$rel.ForeignTable.ColumnNameGo}}} values := []interface{}{{"{"}}o.{{$rel.LocalTable.ColumnNameGo}}, rel.{{$rel.ForeignTable.ColumnNameGo}}}
if boil.DebugMode { if boil.DebugMode {
fmt.Fprintln(boil.DebugWriter, query) fmt.Fprintln(boil.DebugWriter, query)
@ -49,32 +49,32 @@ func ({{$rel.Function.Receiver}} *{{$rel.LocalTable.NameGo}}) Add{{$rel.Function
} }
{{end -}} {{end -}}
if {{$rel.Function.Receiver}}.R == nil { if o.R == nil {
{{$rel.Function.Receiver}}.R = &{{$localNameSingular}}R{ o.R = &{{$localNameSingular}}R{
{{$rel.Function.Name}}: related, {{$rel.Function.Name}}: related,
} }
} else { } else {
{{$rel.Function.Receiver}}.R.{{$rel.Function.Name}} = append({{$rel.Function.Receiver}}.R.{{$rel.Function.Name}}, related...) o.R.{{$rel.Function.Name}} = append(o.R.{{$rel.Function.Name}}, related...)
} }
{{if .ToJoinTable -}} {{if .ToJoinTable -}}
for _, rel := range related { for _, rel := range related {
if rel.R == nil { if rel.R == nil {
rel.R = &{{$foreignNameSingular}}R{ rel.R = &{{$foreignNameSingular}}R{
{{$rel.Function.ForeignName}}: {{$rel.LocalTable.NameGo}}Slice{{"{"}}{{$rel.Function.Receiver}}{{"}"}}, {{$rel.Function.ForeignName}}: {{$rel.LocalTable.NameGo}}Slice{{"{"}}o{{"}"}},
} }
} else { } else {
rel.R.{{$rel.Function.ForeignName}} = append(rel.R.{{$rel.Function.ForeignName}}, {{$rel.Function.Receiver}}) rel.R.{{$rel.Function.ForeignName}} = append(rel.R.{{$rel.Function.ForeignName}}, o)
} }
} }
{{else -}} {{else -}}
for _, rel := range related { for _, rel := range related {
if rel.R == nil { if rel.R == nil {
rel.R = &{{$foreignNameSingular}}R{ rel.R = &{{$foreignNameSingular}}R{
{{$rel.Function.ForeignName}}: {{$rel.Function.Receiver}}, {{$rel.Function.ForeignName}}: o,
} }
} else { } else {
rel.R.{{$rel.Function.ForeignName}} = {{$rel.Function.Receiver}} rel.R.{{$rel.Function.ForeignName}} = o
} }
} }
{{end -}} {{end -}}
@ -86,16 +86,16 @@ func ({{$rel.Function.Receiver}} *{{$rel.LocalTable.NameGo}}) Add{{$rel.Function
// Set{{$rel.Function.Name}} removes all previously related items of the // Set{{$rel.Function.Name}} removes all previously related items of the
// {{$table.Name | singular}} replacing them completely with the passed // {{$table.Name | singular}} replacing them completely with the passed
// in related items, optionally inserting them as new records. // in related items, optionally inserting them as new records.
// Sets {{$rel.Function.Receiver}}.R.{{$rel.Function.ForeignName}}'s {{$rel.Function.Name}} accordingly. // Sets o.R.{{$rel.Function.ForeignName}}'s {{$rel.Function.Name}} accordingly.
// Replaces {{$rel.Function.Receiver}}.R.{{$rel.Function.Name}} with related. // Replaces o.R.{{$rel.Function.Name}} with related.
// Sets related.R.{{$rel.Function.ForeignName}}'s {{$rel.Function.Name}} accordingly. // Sets related.R.{{$rel.Function.ForeignName}}'s {{$rel.Function.Name}} accordingly.
func ({{$rel.Function.Receiver}} *{{$rel.LocalTable.NameGo}}) Set{{$rel.Function.Name}}(exec boil.Executor, insert bool, related ...*{{$rel.ForeignTable.NameGo}}) error { func (o *{{$rel.LocalTable.NameGo}}) Set{{$rel.Function.Name}}(exec boil.Executor, insert bool, related ...*{{$rel.ForeignTable.NameGo}}) error {
{{if .ToJoinTable -}} {{if .ToJoinTable -}}
query := "delete from {{.JoinTable | $dot.SchemaTable}} where {{.JoinLocalColumn | $dot.Quotes}} = {{if $dot.Dialect.IndexPlaceholders}}$1{{else}}?{{end}}" query := "delete from {{.JoinTable | $dot.SchemaTable}} where {{.JoinLocalColumn | $dot.Quotes}} = {{if $dot.Dialect.IndexPlaceholders}}$1{{else}}?{{end}}"
values := []interface{}{{"{"}}{{$rel.Function.Receiver}}.{{$rel.LocalTable.ColumnNameGo}}} values := []interface{}{{"{"}}o.{{$rel.LocalTable.ColumnNameGo}}}
{{else -}} {{else -}}
query := "update {{.ForeignTable | $dot.SchemaTable}} set {{.ForeignColumn | $dot.Quotes}} = null where {{.ForeignColumn | $dot.Quotes}} = {{if $dot.Dialect.IndexPlaceholders}}$1{{else}}?{{end}}" query := "update {{.ForeignTable | $dot.SchemaTable}} set {{.ForeignColumn | $dot.Quotes}} = null where {{.ForeignColumn | $dot.Quotes}} = {{if $dot.Dialect.IndexPlaceholders}}$1{{else}}?{{end}}"
values := []interface{}{{"{"}}{{$rel.Function.Receiver}}.{{$rel.LocalTable.ColumnNameGo}}} values := []interface{}{{"{"}}o.{{$rel.LocalTable.ColumnNameGo}}}
{{end -}} {{end -}}
if boil.DebugMode { if boil.DebugMode {
fmt.Fprintln(boil.DebugWriter, query) fmt.Fprintln(boil.DebugWriter, query)
@ -108,11 +108,11 @@ func ({{$rel.Function.Receiver}} *{{$rel.LocalTable.NameGo}}) Set{{$rel.Function
} }
{{if .ToJoinTable -}} {{if .ToJoinTable -}}
remove{{$rel.LocalTable.NameGo}}From{{$rel.ForeignTable.NameGo}}Slice({{$rel.Function.Receiver}}, related) remove{{$rel.LocalTable.NameGo}}From{{$rel.ForeignTable.NameGo}}Slice(o, related)
{{$rel.Function.Receiver}}.R.{{$rel.Function.Name}} = nil o.R.{{$rel.Function.Name}} = nil
{{else -}} {{else -}}
if {{$rel.Function.Receiver}}.R != nil { if o.R != nil {
for _, rel := range {{$rel.Function.Receiver}}.R.{{$rel.Function.Name}} { for _, rel := range o.R.{{$rel.Function.Name}} {
rel.{{$rel.ForeignTable.ColumnNameGo}}.Valid = false rel.{{$rel.ForeignTable.ColumnNameGo}}.Valid = false
if rel.R == nil { if rel.R == nil {
continue continue
@ -121,24 +121,24 @@ func ({{$rel.Function.Receiver}} *{{$rel.LocalTable.NameGo}}) Set{{$rel.Function
rel.R.{{$rel.Function.ForeignName}} = nil rel.R.{{$rel.Function.ForeignName}} = nil
} }
{{$rel.Function.Receiver}}.R.{{$rel.Function.Name}} = nil o.R.{{$rel.Function.Name}} = nil
} }
{{end -}} {{end -}}
return {{$rel.Function.Receiver}}.Add{{$rel.Function.Name}}(exec, insert, related...) return o.Add{{$rel.Function.Name}}(exec, insert, related...)
} }
// Remove{{$rel.Function.Name}} relationships from objects passed in. // Remove{{$rel.Function.Name}} relationships from objects passed in.
// Removes related items from R.{{$rel.Function.Name}} (uses pointer comparison, removal does not keep order) // Removes related items from R.{{$rel.Function.Name}} (uses pointer comparison, removal does not keep order)
// Sets related.R.{{$rel.Function.ForeignName}}. // Sets related.R.{{$rel.Function.ForeignName}}.
func ({{$rel.Function.Receiver}} *{{$rel.LocalTable.NameGo}}) Remove{{$rel.Function.Name}}(exec boil.Executor, related ...*{{$rel.ForeignTable.NameGo}}) error { func (o *{{$rel.LocalTable.NameGo}}) Remove{{$rel.Function.Name}}(exec boil.Executor, related ...*{{$rel.ForeignTable.NameGo}}) error {
var err error var err error
{{if .ToJoinTable -}} {{if .ToJoinTable -}}
query := fmt.Sprintf( query := fmt.Sprintf(
"delete from {{.JoinTable | $dot.SchemaTable}} where {{.JoinLocalColumn | $dot.Quotes}} = {{if $dot.Dialect.IndexPlaceholders}}$1{{else}}?{{end}} and {{.JoinForeignColumn | $dot.Quotes}} in (%s)", "delete from {{.JoinTable | $dot.SchemaTable}} where {{.JoinLocalColumn | $dot.Quotes}} = {{if $dot.Dialect.IndexPlaceholders}}$1{{else}}?{{end}} and {{.JoinForeignColumn | $dot.Quotes}} in (%s)",
strmangle.Placeholders(dialect.IndexPlaceholders, len(related), 1, 1), strmangle.Placeholders(dialect.IndexPlaceholders, len(related), 1, 1),
) )
values := []interface{}{{"{"}}{{$rel.Function.Receiver}}.{{$rel.LocalTable.ColumnNameGo}}} values := []interface{}{{"{"}}o.{{$rel.LocalTable.ColumnNameGo}}}
if boil.DebugMode { if boil.DebugMode {
fmt.Fprintln(boil.DebugWriter, query) fmt.Fprintln(boil.DebugWriter, query)
@ -164,23 +164,23 @@ func ({{$rel.Function.Receiver}} *{{$rel.LocalTable.NameGo}}) Remove{{$rel.Funct
{{end -}} {{end -}}
{{if .ToJoinTable -}} {{if .ToJoinTable -}}
remove{{$rel.LocalTable.NameGo}}From{{$rel.ForeignTable.NameGo}}Slice({{$rel.Function.Receiver}}, related) remove{{$rel.LocalTable.NameGo}}From{{$rel.ForeignTable.NameGo}}Slice(o, related)
{{end -}} {{end -}}
if {{$rel.Function.Receiver}}.R == nil { if o.R == nil {
return nil return nil
} }
for _, rel := range related { for _, rel := range related {
for i, ri := range {{$rel.Function.Receiver}}.R.{{$rel.Function.Name}} { for i, ri := range o.R.{{$rel.Function.Name}} {
if rel != ri { if rel != ri {
continue continue
} }
ln := len({{$rel.Function.Receiver}}.R.{{$rel.Function.Name}}) ln := len(o.R.{{$rel.Function.Name}})
if ln > 1 && i < ln-1 { if ln > 1 && i < ln-1 {
{{$rel.Function.Receiver}}.R.{{$rel.Function.Name}}[i] = {{$rel.Function.Receiver}}.R.{{$rel.Function.Name}}[ln-1] o.R.{{$rel.Function.Name}}[i] = o.R.{{$rel.Function.Name}}[ln-1]
} }
{{$rel.Function.Receiver}}.R.{{$rel.Function.Name}} = {{$rel.Function.Receiver}}.R.{{$rel.Function.Name}}[:ln-1] o.R.{{$rel.Function.Name}} = o.R.{{$rel.Function.Name}}[:ln-1]
break break
} }
} }
@ -189,16 +189,16 @@ func ({{$rel.Function.Receiver}} *{{$rel.LocalTable.NameGo}}) Remove{{$rel.Funct
} }
{{if .ToJoinTable -}} {{if .ToJoinTable -}}
func remove{{$rel.LocalTable.NameGo}}From{{$rel.ForeignTable.NameGo}}Slice({{$rel.Function.Receiver}} *{{$rel.LocalTable.NameGo}}, related []*{{$rel.ForeignTable.NameGo}}) { func remove{{$rel.LocalTable.NameGo}}From{{$rel.ForeignTable.NameGo}}Slice(o *{{$rel.LocalTable.NameGo}}, related []*{{$rel.ForeignTable.NameGo}}) {
for _, rel := range related { for _, rel := range related {
if rel.R == nil { if rel.R == nil {
continue continue
} }
for i, ri := range rel.R.{{$rel.Function.ForeignName}} { for i, ri := range rel.R.{{$rel.Function.ForeignName}} {
{{if $rel.Function.UsesBytes -}} {{if $rel.Function.UsesBytes -}}
if 0 != bytes.Compare({{$rel.Function.Receiver}}.{{$rel.Function.LocalAssignment}}, ri.{{$rel.Function.LocalAssignment}}) { if 0 != bytes.Compare(o.{{$rel.Function.LocalAssignment}}, ri.{{$rel.Function.LocalAssignment}}) {
{{else -}} {{else -}}
if {{$rel.Function.Receiver}}.{{$rel.Function.LocalAssignment}} != ri.{{$rel.Function.LocalAssignment}} { if o.{{$rel.Function.LocalAssignment}} != ri.{{$rel.Function.LocalAssignment}} {
{{end -}} {{end -}}
continue continue
} }

View file

@ -31,7 +31,6 @@ type TxtToOne struct {
ForeignName string ForeignName string
Varname string Varname string
Receiver string
UsesBytes bool UsesBytes bool
LocalAssignment string LocalAssignment string
@ -60,7 +59,6 @@ func txtsFromFKey(tables []bdb.Table, table bdb.Table, fkey bdb.ForeignKey) TxtT
} }
r.Function.ForeignName = mkFunctionName(strmangle.Singular(fkey.ForeignTable), strmangle.TitleCase(plurality(fkey.Table)), fkey.Column, false) r.Function.ForeignName = mkFunctionName(strmangle.Singular(fkey.ForeignTable), strmangle.TitleCase(plurality(fkey.Table)), fkey.Column, false)
r.Function.Varname = strmangle.CamelCase(strmangle.Singular(fkey.ForeignTable)) r.Function.Varname = strmangle.CamelCase(strmangle.Singular(fkey.ForeignTable))
r.Function.Receiver = strings.ToLower(table.Name[:1])
if fkey.Nullable { if fkey.Nullable {
col := table.GetColumn(fkey.Column) col := table.GetColumn(fkey.Column)
@ -132,7 +130,6 @@ type TxtToMany struct {
Function struct { Function struct {
Name string Name string
ForeignName string ForeignName string
Receiver string
UsesBytes bool UsesBytes bool
@ -156,7 +153,6 @@ func txtsFromToMany(tables []bdb.Table, table bdb.Table, rel bdb.ToManyRelations
r.ForeignTable.Slice = fmt.Sprintf("%sSlice", strmangle.TitleCase(r.ForeignTable.NameSingular)) r.ForeignTable.Slice = fmt.Sprintf("%sSlice", strmangle.TitleCase(r.ForeignTable.NameSingular))
r.ForeignTable.NameHumanReadable = strings.Replace(rel.ForeignTable, "_", " ", -1) r.ForeignTable.NameHumanReadable = strings.Replace(rel.ForeignTable, "_", " ", -1)
r.Function.Receiver = strings.ToLower(table.Name[:1])
r.Function.Name = mkFunctionName(r.LocalTable.NameSingular, r.ForeignTable.NamePluralGo, rel.ForeignColumn, rel.ToJoinTable) r.Function.Name = mkFunctionName(r.LocalTable.NameSingular, r.ForeignTable.NamePluralGo, rel.ForeignColumn, rel.ToJoinTable)
plurality := strmangle.Singular plurality := strmangle.Singular
foreignNamingColumn := rel.ForeignColumn foreignNamingColumn := rel.ForeignColumn

View file

@ -35,7 +35,6 @@ func TestTxtsFromOne(t *testing.T) {
expect.Function.Name = "Pilot" expect.Function.Name = "Pilot"
expect.Function.ForeignName = "Jet" expect.Function.ForeignName = "Jet"
expect.Function.Varname = "pilot" expect.Function.Varname = "pilot"
expect.Function.Receiver = "j"
expect.Function.LocalAssignment = "PilotID.Int" expect.Function.LocalAssignment = "PilotID.Int"
expect.Function.ForeignAssignment = "ID" expect.Function.ForeignAssignment = "ID"
@ -60,7 +59,6 @@ func TestTxtsFromOne(t *testing.T) {
expect.Function.Name = "Airport" expect.Function.Name = "Airport"
expect.Function.ForeignName = "Jets" expect.Function.ForeignName = "Jets"
expect.Function.Varname = "airport" expect.Function.Varname = "airport"
expect.Function.Receiver = "j"
expect.Function.LocalAssignment = "AirportID" expect.Function.LocalAssignment = "AirportID"
expect.Function.ForeignAssignment = "ID" expect.Function.ForeignAssignment = "ID"
@ -112,7 +110,6 @@ func TestTxtsFromOneToOne(t *testing.T) {
expect.Function.Name = "Jet" expect.Function.Name = "Jet"
expect.Function.ForeignName = "Pilot" expect.Function.ForeignName = "Pilot"
expect.Function.Varname = "jet" expect.Function.Varname = "jet"
expect.Function.Receiver = "p"
expect.Function.LocalAssignment = "ID" expect.Function.LocalAssignment = "ID"
expect.Function.ForeignAssignment = "PilotID.Int" expect.Function.ForeignAssignment = "PilotID.Int"
@ -146,7 +143,6 @@ func TestTxtsFromMany(t *testing.T) {
expect.Function.Name = "Licenses" expect.Function.Name = "Licenses"
expect.Function.ForeignName = "Pilot" expect.Function.ForeignName = "Pilot"
expect.Function.Receiver = "p"
expect.Function.LocalAssignment = "ID" expect.Function.LocalAssignment = "ID"
expect.Function.ForeignAssignment = "PilotID" expect.Function.ForeignAssignment = "PilotID"
@ -169,7 +165,6 @@ func TestTxtsFromMany(t *testing.T) {
expect.Function.Name = "Languages" expect.Function.Name = "Languages"
expect.Function.ForeignName = "Pilots" expect.Function.ForeignName = "Pilots"
expect.Function.Receiver = "p"
expect.Function.LocalAssignment = "ID" expect.Function.LocalAssignment = "ID"
expect.Function.ForeignAssignment = "ID" expect.Function.ForeignAssignment = "ID"