From 3474602ab541e9d5f91d73c547524d3b247df5b8 Mon Sep 17 00:00:00 2001 From: Aaron L Date: Mon, 19 Sep 2016 18:59:46 -0700 Subject: [PATCH] Correct bits here and there from last commits --- README.md | 9 +++------ templates_test/relationship_one_to_one.tpl | 8 ++++---- templates_test/relationship_to_many.tpl | 4 ++-- templates_test/relationship_to_one.tpl | 12 ++++++------ text_helpers.go | 6 ------ text_helpers_test.go | 7 ------- 6 files changed, 15 insertions(+), 31 deletions(-) diff --git a/README.md b/README.md index 7523671..d8a0167 100644 --- a/README.md +++ b/README.md @@ -179,9 +179,9 @@ fmt.Println(len(users.R.FavoriteMovies)) a *composite primary key* that encompasses both foreign table foreign keys. For example, on a join table named `user_videos` you should have: `primary key(user_id, video_id)`, with both `user_id` and `video_id` being foreign key columns to the users and videos tables respectively. -* For MySQL if using the `github.com/go-sql-driver/mysql` driver, please activate +* For MySQL if using the `github.com/go-sql-driver/mysql` driver, please activate [time.Time parsing](https://github.com/go-sql-driver/mysql#timetime-support) when making your - MySQL database connection. SQLBoiler uses `time.Time` and `null.Time` to represent time in + MySQL database connection. SQLBoiler uses `time.Time` and `null.Time` to represent time in it's models and without this enabled any models with `DATE`/`DATETIME` columns will not work. ### Pro Tips @@ -1066,10 +1066,7 @@ Please note that multi-dimensional Postgres ARRAY types are not supported at thi #### Why aren't my time.Time or null.Time fields working in MySQL? -For MySQL if using the `github.com/go-sql-driver/mysql` driver, please activate -[time.Time parsing](https://github.com/go-sql-driver/mysql#timetime-support) when making your -MySQL database connection. SQLBoiler uses `time.Time` and `null.Time` to represent time in -it's models and without this enabled any models with `DATE`/`DATETIME` columns will not work. +You *must* use a DSN flag in MySQL connections, see: [Requirements](#requirements) #### Where is the homepage? diff --git a/templates_test/relationship_one_to_one.tpl b/templates_test/relationship_one_to_one.tpl index 7712476..83e55f3 100644 --- a/templates_test/relationship_one_to_one.tpl +++ b/templates_test/relationship_one_to_one.tpl @@ -3,8 +3,8 @@ {{- $dot := . -}} {{- range .Table.ToOneRelationships -}} {{- $txt := txtsFromOneToOne $dot.Tables $dot.Table . -}} - {{- $foreignNameSingular := $txt.ForeignTable.Name | singular | camelCase -}} - {{- $localNameSingular := $txt.LocalTable.Name | singular | camelCase -}} + {{- $varNameSingular := .Table | singular | camelCase -}} + {{- $foreignVarNameSingular := .ForeignTable | singular | camelCase -}} func test{{$txt.LocalTable.NameGo}}OneToOne{{$txt.ForeignTable.NameGo}}_{{$txt.Function.Name}}(t *testing.T) { tx := MustTx(boil.Begin()) defer tx.Rollback() @@ -13,10 +13,10 @@ func test{{$txt.LocalTable.NameGo}}OneToOne{{$txt.ForeignTable.NameGo}}_{{$txt.F var local {{$txt.LocalTable.NameGo}} seed := randomize.NewSeed() - if err := randomize.Struct(seed, &foreign, {{$foreignNameSingular}}DBTypes, true, {{$foreignNameSingular}}ColumnsWithDefault...); err != nil { + if err := randomize.Struct(seed, &foreign, {{$foreignVarNameSingular}}DBTypes, true, {{$foreignVarNameSingular}}ColumnsWithDefault...); err != nil { t.Errorf("Unable to randomize {{$txt.ForeignTable.NameGo}} struct: %s", err) } - if err := randomize.Struct(seed, &local, {{$localNameSingular}}DBTypes, true, {{$localNameSingular}}ColumnsWithDefault...); err != nil { + if err := randomize.Struct(seed, &local, {{$varNameSingular}}DBTypes, true, {{$varNameSingular}}ColumnsWithDefault...); err != nil { t.Errorf("Unable to randomize {{$txt.LocalTable.NameGo}} struct: %s", err) } diff --git a/templates_test/relationship_to_many.tpl b/templates_test/relationship_to_many.tpl index 40f3916..ad3c7ce 100644 --- a/templates_test/relationship_to_many.tpl +++ b/templates_test/relationship_to_many.tpl @@ -4,7 +4,7 @@ {{- $table := .Table }} {{- range .Table.ToManyRelationships -}} {{- $txt := txtsFromToMany $dot.Tables $table .}} - {{- $localNameSingular := $txt.LocalTable.Name | singular | camelCase -}} + {{- $varNameSingular := .Table | singular | camelCase -}} func test{{$txt.LocalTable.NameGo}}ToMany{{$txt.Function.Name}}(t *testing.T) { var err error tx := MustTx(boil.Begin()) @@ -14,7 +14,7 @@ func test{{$txt.LocalTable.NameGo}}ToMany{{$txt.Function.Name}}(t *testing.T) { var b, c {{$txt.ForeignTable.NameGo}} seed := randomize.NewSeed() - if err = randomize.Struct(seed, &a, {{$localNameSingular}}DBTypes, true, {{$localNameSingular}}ColumnsWithDefault...); err != nil { + if err = randomize.Struct(seed, &a, {{$varNameSingular}}DBTypes, true, {{$varNameSingular}}ColumnsWithDefault...); err != nil { t.Errorf("Unable to randomize {{$txt.LocalTable.NameGo}} struct: %s", err) } diff --git a/templates_test/relationship_to_one.tpl b/templates_test/relationship_to_one.tpl index add3fc5..2ad90b9 100644 --- a/templates_test/relationship_to_one.tpl +++ b/templates_test/relationship_to_one.tpl @@ -3,8 +3,8 @@ {{- $dot := . -}} {{- range .Table.FKeys -}} {{- $txt := txtsFromFKey $dot.Tables $dot.Table . -}} - {{- $foreignNameSingular := $txt.ForeignTable.Name | singular | camelCase -}} - {{- $localNameSingular := $txt.LocalTable.Name | singular | camelCase -}} + {{- $varNameSingular := .Table | singular | camelCase -}} + {{- $foreignVarNameSingular := .ForeignTable | singular | camelCase -}} func test{{$txt.LocalTable.NameGo}}ToOne{{$txt.ForeignTable.NameGo}}_{{$txt.Function.Name}}(t *testing.T) { tx := MustTx(boil.Begin()) defer tx.Rollback() @@ -13,12 +13,12 @@ func test{{$txt.LocalTable.NameGo}}ToOne{{$txt.ForeignTable.NameGo}}_{{$txt.Func var foreign {{$txt.ForeignTable.NameGo}} seed := randomize.NewSeed() - if err := randomize.Struct(seed, &foreign, {{$foreignNameSingular}}DBTypes, true, {{$foreignNameSingular}}ColumnsWithDefault...); err != nil { - t.Errorf("Unable to randomize {{$txt.ForeignTable.NameGo}} struct: %s", err) - } - if err := randomize.Struct(seed, &local, {{$localNameSingular}}DBTypes, true, {{$localNameSingular}}ColumnsWithDefault...); err != nil { + if err := randomize.Struct(seed, &local, {{$varNameSingular}}DBTypes, true, {{$varNameSingular}}ColumnsWithDefault...); err != nil { t.Errorf("Unable to randomize {{$txt.LocalTable.NameGo}} struct: %s", err) } + if err := randomize.Struct(seed, &foreign, {{$foreignVarNameSingular}}DBTypes, true, {{$foreignVarNameSingular}}ColumnsWithDefault...); err != nil { + t.Errorf("Unable to randomize {{$txt.ForeignTable.NameGo}} struct: %s", err) + } {{if .Nullable -}} local.{{$txt.LocalTable.ColumnNameGo}}.Valid = true diff --git a/text_helpers.go b/text_helpers.go index d157609..f71bec3 100644 --- a/text_helpers.go +++ b/text_helpers.go @@ -14,7 +14,6 @@ type TxtToOne struct { ForeignKey bdb.ForeignKey LocalTable struct { - Name string NameGo string ColumnNameGo string } @@ -45,7 +44,6 @@ func txtsFromFKey(tables []bdb.Table, table bdb.Table, fkey bdb.ForeignKey) TxtT r.ForeignKey = fkey - r.LocalTable.Name = table.Name r.LocalTable.NameGo = strmangle.TitleCase(strmangle.Singular(table.Name)) r.LocalTable.ColumnNameGo = strmangle.TitleCase(strmangle.Singular(fkey.Column)) @@ -117,14 +115,12 @@ func txtsFromOneToOne(tables []bdb.Table, table bdb.Table, oneToOne bdb.ToOneRel // TxtToMany contains text that will be used by many-to-one relationships. type TxtToMany struct { LocalTable struct { - Name string NameGo string NameSingular string ColumnNameGo string } ForeignTable struct { - Name string NameGo string NameSingular string NamePluralGo string @@ -149,12 +145,10 @@ type TxtToMany struct { // transformation in advance for a given relationship. func txtsFromToMany(tables []bdb.Table, table bdb.Table, rel bdb.ToManyRelationship) TxtToMany { r := TxtToMany{} - r.LocalTable.Name = table.Name r.LocalTable.NameSingular = strmangle.Singular(table.Name) r.LocalTable.NameGo = strmangle.TitleCase(r.LocalTable.NameSingular) r.LocalTable.ColumnNameGo = strmangle.TitleCase(rel.Column) - r.ForeignTable.Name = rel.ForeignTable r.ForeignTable.NameSingular = strmangle.Singular(rel.ForeignTable) r.ForeignTable.NamePluralGo = strmangle.TitleCase(strmangle.Plural(rel.ForeignTable)) r.ForeignTable.NameGo = strmangle.TitleCase(r.ForeignTable.NameSingular) diff --git a/text_helpers_test.go b/text_helpers_test.go index d1ffb3a..a8591dc 100644 --- a/text_helpers_test.go +++ b/text_helpers_test.go @@ -23,7 +23,6 @@ func TestTxtsFromOne(t *testing.T) { expect.ForeignKey = jets.FKeys[0] - expect.LocalTable.Name = "jets" expect.LocalTable.NameGo = "Jet" expect.LocalTable.ColumnNameGo = "PilotID" @@ -49,7 +48,6 @@ func TestTxtsFromOne(t *testing.T) { expect = TxtToOne{} expect.ForeignKey = jets.FKeys[1] - expect.LocalTable.Name = "jets" expect.LocalTable.NameGo = "Jet" expect.LocalTable.ColumnNameGo = "AirportID" @@ -102,7 +100,6 @@ func TestTxtsFromOneToOne(t *testing.T) { ForeignColumnUnique: false, } - expect.LocalTable.Name = "pilots" expect.LocalTable.NameGo = "Pilot" expect.LocalTable.ColumnNameGo = "ID" @@ -136,12 +133,10 @@ func TestTxtsFromMany(t *testing.T) { pilots := bdb.GetTable(tables, "pilots") texts := txtsFromToMany(tables, pilots, pilots.ToManyRelationships[0]) expect := TxtToMany{} - expect.LocalTable.Name = "pilots" expect.LocalTable.NameGo = "Pilot" expect.LocalTable.NameSingular = "pilot" expect.LocalTable.ColumnNameGo = "ID" - expect.ForeignTable.Name = "licenses" expect.ForeignTable.NameGo = "License" expect.ForeignTable.NameSingular = "license" expect.ForeignTable.NamePluralGo = "Licenses" @@ -161,12 +156,10 @@ func TestTxtsFromMany(t *testing.T) { texts = txtsFromToMany(tables, pilots, pilots.ToManyRelationships[1]) expect = TxtToMany{} - expect.LocalTable.Name = "pilots" expect.LocalTable.NameGo = "Pilot" expect.LocalTable.NameSingular = "pilot" expect.LocalTable.ColumnNameGo = "ID" - expect.ForeignTable.Name = "languages" expect.ForeignTable.NameGo = "Language" expect.ForeignTable.NameSingular = "language" expect.ForeignTable.NamePluralGo = "Languages"