Rename ReverseInserts -> OneToOne

- Fix bug & failing test
- Skip WIP test
This commit is contained in:
Aaron L 2016-08-28 00:27:50 -07:00
parent 625dee4648
commit 947081c579
5 changed files with 10 additions and 9 deletions

View file

@ -27,7 +27,7 @@ func ({{.Function.Receiver}} *{{.LocalTable.NameGo}}) Set{{.Function.Name}}(exec
{{.Function.Receiver}}.R.{{.Function.Name}} = related
}
{{if .ForeignKey.Unique -}}
{{if (or .ForeignKey.Unique .Function.OneToOne) -}}
if related.R == nil {
related.R = &{{.ForeignTable.NameGo}}R{
{{.Function.ForeignName}}: {{.Function.Receiver}},

View file

@ -11,6 +11,7 @@
{{- $rel := textsFromRelationship $dot.Tables $table .}}
func test{{$rel.LocalTable.NameGo}}ToManyAddOp{{$rel.Function.Name}}(t *testing.T) {
t.Skip("WIP")
var err error
tx := MustTx(boil.Begin())

View file

@ -12,7 +12,7 @@ func test{{.LocalTable.NameGo}}ToOne{{.ForeignTable.NameGo}}_{{.Function.Name}}(
foreign.{{.ForeignKey.ForeignColumn | titleCase}}.Valid = true
{{end}}
{{if not .Function.ReverseInserts -}}
{{if not .Function.OneToOne -}}
if err := foreign.Insert(tx); err != nil {
t.Fatal(err)
}

View file

@ -30,9 +30,9 @@ type RelationshipToOneTexts struct {
Name string
ForeignName string
Varname string
Receiver string
ReverseInserts bool
Varname string
Receiver string
OneToOne bool
LocalAssignment string
ForeignAssignment string
@ -98,7 +98,7 @@ func textsFromOneToOneRelationship(packageName string, tables []bdb.Table, table
rel := textsFromForeignKey(packageName, tables, table, fkey)
rel.Function.Name = strmangle.TitleCase(strmangle.Singular(toMany.ForeignTable))
rel.Function.ForeignName = mkFunctionName(strmangle.Singular(toMany.Table), strmangle.TitleCase(strmangle.Singular(toMany.Table)), toMany.ForeignColumn, false)
rel.Function.ReverseInserts = true
rel.Function.OneToOne = true
return rel
}

View file

@ -37,7 +37,7 @@ func TestTextsFromForeignKey(t *testing.T) {
expect.Function.ForeignName = "Jet"
expect.Function.Varname = "pilot"
expect.Function.Receiver = "j"
expect.Function.ReverseInserts = false
expect.Function.OneToOne = false
expect.Function.LocalAssignment = "PilotID.Int"
expect.Function.ForeignAssignment = "ID"
@ -64,7 +64,7 @@ func TestTextsFromForeignKey(t *testing.T) {
expect.Function.ForeignName = "Jets"
expect.Function.Varname = "airport"
expect.Function.Receiver = "j"
expect.Function.ReverseInserts = false
expect.Function.OneToOne = false
expect.Function.LocalAssignment = "AirportID"
expect.Function.ForeignAssignment = "ID"
@ -117,7 +117,7 @@ func TestTextsFromOneToOneRelationship(t *testing.T) {
expect.Function.ForeignName = "Pilot"
expect.Function.Varname = "jet"
expect.Function.Receiver = "p"
expect.Function.ReverseInserts = true
expect.Function.OneToOne = true
expect.Function.LocalAssignment = "ID"
expect.Function.ForeignAssignment = "PilotID.Int"