Fix receiver lint errs
This commit is contained in:
parent
f48b041daa
commit
522cb6824c
8 changed files with 84 additions and 93 deletions
|
@ -5,14 +5,14 @@
|
|||
{{- $txt := txtsFromFKey $dot.Tables $dot.Table . -}}
|
||||
{{- $varNameSingular := .ForeignTable | singular | camelCase -}}
|
||||
// {{$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 {
|
||||
return {{$txt.Function.Receiver}}.{{$txt.Function.Name}}(boil.GetDB(), mods...)
|
||||
func (o *{{$txt.LocalTable.NameGo}}) {{$txt.Function.Name}}G(mods ...qm.QueryMod) {{$varNameSingular}}Query {
|
||||
return o.{{$txt.Function.Name}}(boil.GetDB(), mods...)
|
||||
}
|
||||
|
||||
// {{$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{
|
||||
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...)
|
||||
|
|
|
@ -5,14 +5,14 @@
|
|||
{{- $txt := txtsFromOneToOne $dot.Tables $dot.Table . -}}
|
||||
{{- $varNameSingular := .ForeignTable | singular | camelCase -}}
|
||||
// {{$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 {
|
||||
return {{$txt.Function.Receiver}}.{{$txt.Function.Name}}(boil.GetDB(), mods...)
|
||||
func (o *{{$txt.LocalTable.NameGo}}) {{$txt.Function.Name}}G(mods ...qm.QueryMod) {{$varNameSingular}}Query {
|
||||
return o.{{$txt.Function.Name}}(boil.GetDB(), mods...)
|
||||
}
|
||||
|
||||
// {{$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{
|
||||
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...)
|
||||
|
|
|
@ -8,13 +8,13 @@
|
|||
{{- $schemaForeignTable := .ForeignTable | $dot.SchemaTable -}}
|
||||
// {{$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}}.
|
||||
func ({{$rel.Function.Receiver}} *{{$rel.LocalTable.NameGo}}) {{$rel.Function.Name}}G(mods ...qm.QueryMod) {{$varNameSingular}}Query {
|
||||
return {{$rel.Function.Receiver}}.{{$rel.Function.Name}}(boil.GetDB(), mods...)
|
||||
func (o *{{$rel.LocalTable.NameGo}}) {{$rel.Function.Name}}G(mods ...qm.QueryMod) {{$varNameSingular}}Query {
|
||||
return o.{{$rel.Function.Name}}(boil.GetDB(), mods...)
|
||||
}
|
||||
|
||||
// {{$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}}.
|
||||
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{
|
||||
qm.Select("{{id 0 | $dot.Quotes}}.*"),
|
||||
}
|
||||
|
@ -26,11 +26,11 @@ func ({{$rel.Function.Receiver}} *{{$rel.LocalTable.NameGo}}) {{$rel.Function.Na
|
|||
{{if .ToJoinTable -}}
|
||||
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.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 -}}
|
||||
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}}
|
||||
|
||||
|
|
|
@ -7,9 +7,9 @@
|
|||
{{- $varNameSingular := .ForeignTable | singular | camelCase -}}
|
||||
{{- $localNameSingular := .Table | singular | camelCase}}
|
||||
// Set{{$txt.Function.Name}} of the {{.Table | singular}} to the related item.
|
||||
// Sets {{$txt.Function.Receiver}}.R.{{$txt.Function.Name}} to related.
|
||||
// Adds {{$txt.Function.Receiver}} 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 {
|
||||
// Sets o.R.{{$txt.Function.Name}} to related.
|
||||
// Adds o to related.R.{{$txt.Function.ForeignName}}.
|
||||
func (o *{{$txt.LocalTable.NameGo}}) Set{{$txt.Function.Name}}(exec boil.Executor, insert bool, related *{{$txt.ForeignTable.NameGo}}) error {
|
||||
var err error
|
||||
if insert {
|
||||
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}}
|
||||
{{$txt.Function.Receiver}}.{{$txt.Function.LocalAssignment}} = related.{{$txt.Function.ForeignAssignment}}
|
||||
oldVal := o.{{$txt.Function.LocalAssignment}}
|
||||
o.{{$txt.Function.LocalAssignment}} = related.{{$txt.Function.ForeignAssignment}}
|
||||
{{if .Nullable -}}
|
||||
{{$txt.Function.Receiver}}.{{$txt.LocalTable.ColumnNameGo}}.Valid = true
|
||||
o.{{$txt.LocalTable.ColumnNameGo}}.Valid = true
|
||||
{{- end}}
|
||||
if err = {{$txt.Function.Receiver}}.Update(exec, "{{.Column}}"); err != nil {
|
||||
{{$txt.Function.Receiver}}.{{$txt.Function.LocalAssignment}} = oldVal
|
||||
if err = o.Update(exec, "{{.Column}}"); err != nil {
|
||||
o.{{$txt.Function.LocalAssignment}} = oldVal
|
||||
{{if .Nullable -}}
|
||||
{{$txt.Function.Receiver}}.{{$txt.LocalTable.ColumnNameGo}}.Valid = false
|
||||
o.{{$txt.LocalTable.ColumnNameGo}}.Valid = false
|
||||
{{- end}}
|
||||
return errors.Wrap(err, "failed to update local table")
|
||||
}
|
||||
|
||||
if {{$txt.Function.Receiver}}.R == nil {
|
||||
{{$txt.Function.Receiver}}.R = &{{$localNameSingular}}R{
|
||||
if o.R == nil {
|
||||
o.R = &{{$localNameSingular}}R{
|
||||
{{$txt.Function.Name}}: related,
|
||||
}
|
||||
} else {
|
||||
{{$txt.Function.Receiver}}.R.{{$txt.Function.Name}} = related
|
||||
o.R.{{$txt.Function.Name}} = related
|
||||
}
|
||||
|
||||
{{if .Unique -}}
|
||||
if related.R == nil {
|
||||
related.R = &{{$varNameSingular}}R{
|
||||
{{$txt.Function.ForeignName}}: {{$txt.Function.Receiver}},
|
||||
{{$txt.Function.ForeignName}}: o,
|
||||
}
|
||||
} else {
|
||||
related.R.{{$txt.Function.ForeignName}} = {{$txt.Function.Receiver}}
|
||||
related.R.{{$txt.Function.ForeignName}} = o
|
||||
}
|
||||
{{else -}}
|
||||
if related.R == nil {
|
||||
related.R = &{{$varNameSingular}}R{
|
||||
{{$txt.Function.ForeignName}}: {{$txt.LocalTable.NameGo}}Slice{{"{"}}{{$txt.Function.Receiver}}{{"}"}},
|
||||
{{$txt.Function.ForeignName}}: {{$txt.LocalTable.NameGo}}Slice{{"{"}}o{{"}"}},
|
||||
}
|
||||
} 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}}
|
||||
|
||||
|
@ -61,18 +61,18 @@ func ({{$txt.Function.Receiver}} *{{$txt.LocalTable.NameGo}}) Set{{$txt.Function
|
|||
|
||||
{{- if .Nullable}}
|
||||
// Remove{{$txt.Function.Name}} relationship.
|
||||
// Sets {{$txt.Function.Receiver}}.R.{{$txt.Function.Name}} to nil.
|
||||
// Removes {{$txt.Function.Receiver}} 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 {
|
||||
// Sets o.R.{{$txt.Function.Name}} to nil.
|
||||
// Removes o from all passed in related items' relationships struct (Optional).
|
||||
func (o *{{$txt.LocalTable.NameGo}}) Remove{{$txt.Function.Name}}(exec boil.Executor, related *{{$txt.ForeignTable.NameGo}}) error {
|
||||
var err error
|
||||
|
||||
{{$txt.Function.Receiver}}.{{$txt.LocalTable.ColumnNameGo}}.Valid = false
|
||||
if err = {{$txt.Function.Receiver}}.Update(exec, "{{.Column}}"); err != nil {
|
||||
{{$txt.Function.Receiver}}.{{$txt.LocalTable.ColumnNameGo}}.Valid = true
|
||||
o.{{$txt.LocalTable.ColumnNameGo}}.Valid = false
|
||||
if err = o.Update(exec, "{{.Column}}"); err != nil {
|
||||
o.{{$txt.LocalTable.ColumnNameGo}}.Valid = true
|
||||
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 {
|
||||
return nil
|
||||
}
|
||||
|
@ -82,9 +82,9 @@ func ({{$txt.Function.Receiver}} *{{$txt.LocalTable.NameGo}}) Remove{{$txt.Funct
|
|||
{{else -}}
|
||||
for i, ri := range related.R.{{$txt.Function.ForeignName}} {
|
||||
{{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 -}}
|
||||
if {{$txt.Function.Receiver}}.{{$txt.Function.LocalAssignment}} != ri.{{$txt.Function.LocalAssignment}} {
|
||||
if o.{{$txt.Function.LocalAssignment}} != ri.{{$txt.Function.LocalAssignment}} {
|
||||
{{end -}}
|
||||
continue
|
||||
}
|
||||
|
|
|
@ -6,13 +6,13 @@
|
|||
{{- $varNameSingular := .ForeignTable | singular | camelCase -}}
|
||||
{{- $localNameSingular := .Table | singular | camelCase}}
|
||||
// Set{{$txt.Function.Name}} of the {{.Table | singular}} to the related item.
|
||||
// Sets {{$txt.Function.Receiver}}.R.{{$txt.Function.Name}} to related.
|
||||
// Adds {{$txt.Function.Receiver}} 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 {
|
||||
// Sets o.R.{{$txt.Function.Name}} to related.
|
||||
// Adds o to related.R.{{$txt.Function.ForeignName}}.
|
||||
func (o *{{$txt.LocalTable.NameGo}}) Set{{$txt.Function.Name}}(exec boil.Executor, insert bool, related *{{$txt.ForeignTable.NameGo}}) error {
|
||||
var err error
|
||||
|
||||
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 -}}
|
||||
related.{{$txt.ForeignTable.ColumnNameGo}}.Valid = true
|
||||
{{- end}}
|
||||
|
@ -35,29 +35,29 @@ func ({{$txt.Function.Receiver}} *{{$txt.LocalTable.NameGo}}) Set{{$txt.Function
|
|||
}
|
||||
}
|
||||
|
||||
if {{$txt.Function.Receiver}}.R == nil {
|
||||
{{$txt.Function.Receiver}}.R = &{{$localNameSingular}}R{
|
||||
if o.R == nil {
|
||||
o.R = &{{$localNameSingular}}R{
|
||||
{{$txt.Function.Name}}: related,
|
||||
}
|
||||
} else {
|
||||
{{$txt.Function.Receiver}}.R.{{$txt.Function.Name}} = related
|
||||
o.R.{{$txt.Function.Name}} = related
|
||||
}
|
||||
|
||||
if related.R == nil {
|
||||
related.R = &{{$varNameSingular}}R{
|
||||
{{$txt.Function.ForeignName}}: {{$txt.Function.Receiver}},
|
||||
{{$txt.Function.ForeignName}}: o,
|
||||
}
|
||||
} else {
|
||||
related.R.{{$txt.Function.ForeignName}} = {{$txt.Function.Receiver}}
|
||||
related.R.{{$txt.Function.ForeignName}} = o
|
||||
}
|
||||
return nil
|
||||
}
|
||||
|
||||
{{- if .ForeignColumnNullable}}
|
||||
// Remove{{$txt.Function.Name}} relationship.
|
||||
// Sets {{$txt.Function.Receiver}}.R.{{$txt.Function.Name}} to nil.
|
||||
// Removes {{$txt.Function.Receiver}} 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 {
|
||||
// Sets o.R.{{$txt.Function.Name}} to nil.
|
||||
// Removes o from all passed in related items' relationships struct (Optional).
|
||||
func (o *{{$txt.LocalTable.NameGo}}) Remove{{$txt.Function.Name}}(exec boil.Executor, related *{{$txt.ForeignTable.NameGo}}) error {
|
||||
var err error
|
||||
|
||||
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")
|
||||
}
|
||||
|
||||
{{$txt.Function.Receiver}}.R.{{$txt.Function.Name}} = nil
|
||||
o.R.{{$txt.Function.Name}} = nil
|
||||
if related == nil || related.R == nil {
|
||||
return nil
|
||||
}
|
||||
|
|
|
@ -10,13 +10,13 @@
|
|||
{{- $foreignNameSingular := .ForeignTable | singular | camelCase}}
|
||||
// Add{{$rel.Function.Name}} adds the given related objects to the existing relationships
|
||||
// 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.
|
||||
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
|
||||
for _, rel := range related {
|
||||
{{if not .ToJoinTable -}}
|
||||
rel.{{$rel.Function.ForeignAssignment}} = {{$rel.Function.Receiver}}.{{$rel.Function.LocalAssignment}}
|
||||
rel.{{$rel.Function.ForeignAssignment}} = o.{{$rel.Function.LocalAssignment}}
|
||||
{{if .ForeignColumnNullable -}}
|
||||
rel.{{$rel.ForeignTable.ColumnNameGo}}.Valid = true
|
||||
{{end -}}
|
||||
|
@ -35,7 +35,7 @@ func ({{$rel.Function.Receiver}} *{{$rel.LocalTable.NameGo}}) Add{{$rel.Function
|
|||
{{if .ToJoinTable -}}
|
||||
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}}"
|
||||
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 {
|
||||
fmt.Fprintln(boil.DebugWriter, query)
|
||||
|
@ -49,32 +49,32 @@ func ({{$rel.Function.Receiver}} *{{$rel.LocalTable.NameGo}}) Add{{$rel.Function
|
|||
}
|
||||
{{end -}}
|
||||
|
||||
if {{$rel.Function.Receiver}}.R == nil {
|
||||
{{$rel.Function.Receiver}}.R = &{{$localNameSingular}}R{
|
||||
if o.R == nil {
|
||||
o.R = &{{$localNameSingular}}R{
|
||||
{{$rel.Function.Name}}: related,
|
||||
}
|
||||
} 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 -}}
|
||||
for _, rel := range related {
|
||||
if rel.R == nil {
|
||||
rel.R = &{{$foreignNameSingular}}R{
|
||||
{{$rel.Function.ForeignName}}: {{$rel.LocalTable.NameGo}}Slice{{"{"}}{{$rel.Function.Receiver}}{{"}"}},
|
||||
{{$rel.Function.ForeignName}}: {{$rel.LocalTable.NameGo}}Slice{{"{"}}o{{"}"}},
|
||||
}
|
||||
} 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 -}}
|
||||
for _, rel := range related {
|
||||
if rel.R == nil {
|
||||
rel.R = &{{$foreignNameSingular}}R{
|
||||
{{$rel.Function.ForeignName}}: {{$rel.Function.Receiver}},
|
||||
{{$rel.Function.ForeignName}}: o,
|
||||
}
|
||||
} else {
|
||||
rel.R.{{$rel.Function.ForeignName}} = {{$rel.Function.Receiver}}
|
||||
rel.R.{{$rel.Function.ForeignName}} = o
|
||||
}
|
||||
}
|
||||
{{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
|
||||
// {{$table.Name | singular}} replacing them completely with the passed
|
||||
// in related items, optionally inserting them as new records.
|
||||
// Sets {{$rel.Function.Receiver}}.R.{{$rel.Function.ForeignName}}'s {{$rel.Function.Name}} accordingly.
|
||||
// Replaces {{$rel.Function.Receiver}}.R.{{$rel.Function.Name}} with related.
|
||||
// Sets o.R.{{$rel.Function.ForeignName}}'s {{$rel.Function.Name}} accordingly.
|
||||
// Replaces o.R.{{$rel.Function.Name}} with related.
|
||||
// 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 -}}
|
||||
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 -}}
|
||||
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 -}}
|
||||
if boil.DebugMode {
|
||||
fmt.Fprintln(boil.DebugWriter, query)
|
||||
|
@ -108,11 +108,11 @@ func ({{$rel.Function.Receiver}} *{{$rel.LocalTable.NameGo}}) Set{{$rel.Function
|
|||
}
|
||||
|
||||
{{if .ToJoinTable -}}
|
||||
remove{{$rel.LocalTable.NameGo}}From{{$rel.ForeignTable.NameGo}}Slice({{$rel.Function.Receiver}}, related)
|
||||
{{$rel.Function.Receiver}}.R.{{$rel.Function.Name}} = nil
|
||||
remove{{$rel.LocalTable.NameGo}}From{{$rel.ForeignTable.NameGo}}Slice(o, related)
|
||||
o.R.{{$rel.Function.Name}} = nil
|
||||
{{else -}}
|
||||
if {{$rel.Function.Receiver}}.R != nil {
|
||||
for _, rel := range {{$rel.Function.Receiver}}.R.{{$rel.Function.Name}} {
|
||||
if o.R != nil {
|
||||
for _, rel := range o.R.{{$rel.Function.Name}} {
|
||||
rel.{{$rel.ForeignTable.ColumnNameGo}}.Valid = false
|
||||
if rel.R == nil {
|
||||
continue
|
||||
|
@ -121,24 +121,24 @@ func ({{$rel.Function.Receiver}} *{{$rel.LocalTable.NameGo}}) Set{{$rel.Function
|
|||
rel.R.{{$rel.Function.ForeignName}} = nil
|
||||
}
|
||||
|
||||
{{$rel.Function.Receiver}}.R.{{$rel.Function.Name}} = nil
|
||||
o.R.{{$rel.Function.Name}} = nil
|
||||
}
|
||||
{{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.
|
||||
// Removes related items from R.{{$rel.Function.Name}} (uses pointer comparison, removal does not keep order)
|
||||
// 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
|
||||
{{if .ToJoinTable -}}
|
||||
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)",
|
||||
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 {
|
||||
fmt.Fprintln(boil.DebugWriter, query)
|
||||
|
@ -164,23 +164,23 @@ func ({{$rel.Function.Receiver}} *{{$rel.LocalTable.NameGo}}) Remove{{$rel.Funct
|
|||
{{end -}}
|
||||
|
||||
{{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 -}}
|
||||
if {{$rel.Function.Receiver}}.R == nil {
|
||||
if o.R == nil {
|
||||
return nil
|
||||
}
|
||||
|
||||
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 {
|
||||
continue
|
||||
}
|
||||
|
||||
ln := len({{$rel.Function.Receiver}}.R.{{$rel.Function.Name}})
|
||||
ln := len(o.R.{{$rel.Function.Name}})
|
||||
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
|
||||
}
|
||||
}
|
||||
|
@ -189,16 +189,16 @@ func ({{$rel.Function.Receiver}} *{{$rel.LocalTable.NameGo}}) Remove{{$rel.Funct
|
|||
}
|
||||
|
||||
{{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 {
|
||||
if rel.R == nil {
|
||||
continue
|
||||
}
|
||||
for i, ri := range rel.R.{{$rel.Function.ForeignName}} {
|
||||
{{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 -}}
|
||||
if {{$rel.Function.Receiver}}.{{$rel.Function.LocalAssignment}} != ri.{{$rel.Function.LocalAssignment}} {
|
||||
if o.{{$rel.Function.LocalAssignment}} != ri.{{$rel.Function.LocalAssignment}} {
|
||||
{{end -}}
|
||||
continue
|
||||
}
|
||||
|
|
|
@ -31,7 +31,6 @@ type TxtToOne struct {
|
|||
ForeignName string
|
||||
|
||||
Varname string
|
||||
Receiver string
|
||||
UsesBytes bool
|
||||
|
||||
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.Varname = strmangle.CamelCase(strmangle.Singular(fkey.ForeignTable))
|
||||
r.Function.Receiver = strings.ToLower(table.Name[:1])
|
||||
|
||||
if fkey.Nullable {
|
||||
col := table.GetColumn(fkey.Column)
|
||||
|
@ -132,7 +130,6 @@ type TxtToMany struct {
|
|||
Function struct {
|
||||
Name string
|
||||
ForeignName string
|
||||
Receiver string
|
||||
|
||||
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.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)
|
||||
plurality := strmangle.Singular
|
||||
foreignNamingColumn := rel.ForeignColumn
|
||||
|
|
|
@ -35,7 +35,6 @@ func TestTxtsFromOne(t *testing.T) {
|
|||
expect.Function.Name = "Pilot"
|
||||
expect.Function.ForeignName = "Jet"
|
||||
expect.Function.Varname = "pilot"
|
||||
expect.Function.Receiver = "j"
|
||||
|
||||
expect.Function.LocalAssignment = "PilotID.Int"
|
||||
expect.Function.ForeignAssignment = "ID"
|
||||
|
@ -60,7 +59,6 @@ func TestTxtsFromOne(t *testing.T) {
|
|||
expect.Function.Name = "Airport"
|
||||
expect.Function.ForeignName = "Jets"
|
||||
expect.Function.Varname = "airport"
|
||||
expect.Function.Receiver = "j"
|
||||
|
||||
expect.Function.LocalAssignment = "AirportID"
|
||||
expect.Function.ForeignAssignment = "ID"
|
||||
|
@ -112,7 +110,6 @@ func TestTxtsFromOneToOne(t *testing.T) {
|
|||
expect.Function.Name = "Jet"
|
||||
expect.Function.ForeignName = "Pilot"
|
||||
expect.Function.Varname = "jet"
|
||||
expect.Function.Receiver = "p"
|
||||
|
||||
expect.Function.LocalAssignment = "ID"
|
||||
expect.Function.ForeignAssignment = "PilotID.Int"
|
||||
|
@ -146,7 +143,6 @@ func TestTxtsFromMany(t *testing.T) {
|
|||
|
||||
expect.Function.Name = "Licenses"
|
||||
expect.Function.ForeignName = "Pilot"
|
||||
expect.Function.Receiver = "p"
|
||||
expect.Function.LocalAssignment = "ID"
|
||||
expect.Function.ForeignAssignment = "PilotID"
|
||||
|
||||
|
@ -169,7 +165,6 @@ func TestTxtsFromMany(t *testing.T) {
|
|||
|
||||
expect.Function.Name = "Languages"
|
||||
expect.Function.ForeignName = "Pilots"
|
||||
expect.Function.Receiver = "p"
|
||||
expect.Function.LocalAssignment = "ID"
|
||||
expect.Function.ForeignAssignment = "ID"
|
||||
|
||||
|
|
Loading…
Reference in a new issue