Correct bits here and there from last commits

This commit is contained in:
Aaron L 2016-09-19 18:59:46 -07:00
parent 4a9e7a1b1a
commit 3474602ab5
6 changed files with 15 additions and 31 deletions

View file

@ -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 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` 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. 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 [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. it's models and without this enabled any models with `DATE`/`DATETIME` columns will not work.
### Pro Tips ### 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? #### 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 You *must* use a DSN flag in MySQL connections, see: [Requirements](#requirements)
[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.
#### Where is the homepage? #### Where is the homepage?

View file

@ -3,8 +3,8 @@
{{- $dot := . -}} {{- $dot := . -}}
{{- range .Table.ToOneRelationships -}} {{- range .Table.ToOneRelationships -}}
{{- $txt := txtsFromOneToOne $dot.Tables $dot.Table . -}} {{- $txt := txtsFromOneToOne $dot.Tables $dot.Table . -}}
{{- $foreignNameSingular := $txt.ForeignTable.Name | singular | camelCase -}} {{- $varNameSingular := .Table | singular | camelCase -}}
{{- $localNameSingular := $txt.LocalTable.Name | singular | camelCase -}} {{- $foreignVarNameSingular := .ForeignTable | singular | camelCase -}}
func test{{$txt.LocalTable.NameGo}}OneToOne{{$txt.ForeignTable.NameGo}}_{{$txt.Function.Name}}(t *testing.T) { func test{{$txt.LocalTable.NameGo}}OneToOne{{$txt.ForeignTable.NameGo}}_{{$txt.Function.Name}}(t *testing.T) {
tx := MustTx(boil.Begin()) tx := MustTx(boil.Begin())
defer tx.Rollback() defer tx.Rollback()
@ -13,10 +13,10 @@ func test{{$txt.LocalTable.NameGo}}OneToOne{{$txt.ForeignTable.NameGo}}_{{$txt.F
var local {{$txt.LocalTable.NameGo}} var local {{$txt.LocalTable.NameGo}}
seed := randomize.NewSeed() 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) 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) t.Errorf("Unable to randomize {{$txt.LocalTable.NameGo}} struct: %s", err)
} }

View file

@ -4,7 +4,7 @@
{{- $table := .Table }} {{- $table := .Table }}
{{- range .Table.ToManyRelationships -}} {{- range .Table.ToManyRelationships -}}
{{- $txt := txtsFromToMany $dot.Tables $table .}} {{- $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) { func test{{$txt.LocalTable.NameGo}}ToMany{{$txt.Function.Name}}(t *testing.T) {
var err error var err error
tx := MustTx(boil.Begin()) 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}} var b, c {{$txt.ForeignTable.NameGo}}
seed := randomize.NewSeed() 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) t.Errorf("Unable to randomize {{$txt.LocalTable.NameGo}} struct: %s", err)
} }

View file

@ -3,8 +3,8 @@
{{- $dot := . -}} {{- $dot := . -}}
{{- range .Table.FKeys -}} {{- range .Table.FKeys -}}
{{- $txt := txtsFromFKey $dot.Tables $dot.Table . -}} {{- $txt := txtsFromFKey $dot.Tables $dot.Table . -}}
{{- $foreignNameSingular := $txt.ForeignTable.Name | singular | camelCase -}} {{- $varNameSingular := .Table | singular | camelCase -}}
{{- $localNameSingular := $txt.LocalTable.Name | singular | camelCase -}} {{- $foreignVarNameSingular := .ForeignTable | singular | camelCase -}}
func test{{$txt.LocalTable.NameGo}}ToOne{{$txt.ForeignTable.NameGo}}_{{$txt.Function.Name}}(t *testing.T) { func test{{$txt.LocalTable.NameGo}}ToOne{{$txt.ForeignTable.NameGo}}_{{$txt.Function.Name}}(t *testing.T) {
tx := MustTx(boil.Begin()) tx := MustTx(boil.Begin())
defer tx.Rollback() defer tx.Rollback()
@ -13,12 +13,12 @@ func test{{$txt.LocalTable.NameGo}}ToOne{{$txt.ForeignTable.NameGo}}_{{$txt.Func
var foreign {{$txt.ForeignTable.NameGo}} var foreign {{$txt.ForeignTable.NameGo}}
seed := randomize.NewSeed() seed := randomize.NewSeed()
if err := randomize.Struct(seed, &foreign, {{$foreignNameSingular}}DBTypes, true, {{$foreignNameSingular}}ColumnsWithDefault...); err != nil { if err := randomize.Struct(seed, &local, {{$varNameSingular}}DBTypes, true, {{$varNameSingular}}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 {
t.Errorf("Unable to randomize {{$txt.LocalTable.NameGo}} struct: %s", err) 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 -}} {{if .Nullable -}}
local.{{$txt.LocalTable.ColumnNameGo}}.Valid = true local.{{$txt.LocalTable.ColumnNameGo}}.Valid = true

View file

@ -14,7 +14,6 @@ type TxtToOne struct {
ForeignKey bdb.ForeignKey ForeignKey bdb.ForeignKey
LocalTable struct { LocalTable struct {
Name string
NameGo string NameGo string
ColumnNameGo string ColumnNameGo string
} }
@ -45,7 +44,6 @@ func txtsFromFKey(tables []bdb.Table, table bdb.Table, fkey bdb.ForeignKey) TxtT
r.ForeignKey = fkey r.ForeignKey = fkey
r.LocalTable.Name = table.Name
r.LocalTable.NameGo = strmangle.TitleCase(strmangle.Singular(table.Name)) r.LocalTable.NameGo = strmangle.TitleCase(strmangle.Singular(table.Name))
r.LocalTable.ColumnNameGo = strmangle.TitleCase(strmangle.Singular(fkey.Column)) 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. // TxtToMany contains text that will be used by many-to-one relationships.
type TxtToMany struct { type TxtToMany struct {
LocalTable struct { LocalTable struct {
Name string
NameGo string NameGo string
NameSingular string NameSingular string
ColumnNameGo string ColumnNameGo string
} }
ForeignTable struct { ForeignTable struct {
Name string
NameGo string NameGo string
NameSingular string NameSingular string
NamePluralGo string NamePluralGo string
@ -149,12 +145,10 @@ type TxtToMany struct {
// transformation in advance for a given relationship. // transformation in advance for a given relationship.
func txtsFromToMany(tables []bdb.Table, table bdb.Table, rel bdb.ToManyRelationship) TxtToMany { func txtsFromToMany(tables []bdb.Table, table bdb.Table, rel bdb.ToManyRelationship) TxtToMany {
r := TxtToMany{} r := TxtToMany{}
r.LocalTable.Name = table.Name
r.LocalTable.NameSingular = strmangle.Singular(table.Name) r.LocalTable.NameSingular = strmangle.Singular(table.Name)
r.LocalTable.NameGo = strmangle.TitleCase(r.LocalTable.NameSingular) r.LocalTable.NameGo = strmangle.TitleCase(r.LocalTable.NameSingular)
r.LocalTable.ColumnNameGo = strmangle.TitleCase(rel.Column) r.LocalTable.ColumnNameGo = strmangle.TitleCase(rel.Column)
r.ForeignTable.Name = rel.ForeignTable
r.ForeignTable.NameSingular = strmangle.Singular(rel.ForeignTable) r.ForeignTable.NameSingular = strmangle.Singular(rel.ForeignTable)
r.ForeignTable.NamePluralGo = strmangle.TitleCase(strmangle.Plural(rel.ForeignTable)) r.ForeignTable.NamePluralGo = strmangle.TitleCase(strmangle.Plural(rel.ForeignTable))
r.ForeignTable.NameGo = strmangle.TitleCase(r.ForeignTable.NameSingular) r.ForeignTable.NameGo = strmangle.TitleCase(r.ForeignTable.NameSingular)

View file

@ -23,7 +23,6 @@ func TestTxtsFromOne(t *testing.T) {
expect.ForeignKey = jets.FKeys[0] expect.ForeignKey = jets.FKeys[0]
expect.LocalTable.Name = "jets"
expect.LocalTable.NameGo = "Jet" expect.LocalTable.NameGo = "Jet"
expect.LocalTable.ColumnNameGo = "PilotID" expect.LocalTable.ColumnNameGo = "PilotID"
@ -49,7 +48,6 @@ func TestTxtsFromOne(t *testing.T) {
expect = TxtToOne{} expect = TxtToOne{}
expect.ForeignKey = jets.FKeys[1] expect.ForeignKey = jets.FKeys[1]
expect.LocalTable.Name = "jets"
expect.LocalTable.NameGo = "Jet" expect.LocalTable.NameGo = "Jet"
expect.LocalTable.ColumnNameGo = "AirportID" expect.LocalTable.ColumnNameGo = "AirportID"
@ -102,7 +100,6 @@ func TestTxtsFromOneToOne(t *testing.T) {
ForeignColumnUnique: false, ForeignColumnUnique: false,
} }
expect.LocalTable.Name = "pilots"
expect.LocalTable.NameGo = "Pilot" expect.LocalTable.NameGo = "Pilot"
expect.LocalTable.ColumnNameGo = "ID" expect.LocalTable.ColumnNameGo = "ID"
@ -136,12 +133,10 @@ func TestTxtsFromMany(t *testing.T) {
pilots := bdb.GetTable(tables, "pilots") pilots := bdb.GetTable(tables, "pilots")
texts := txtsFromToMany(tables, pilots, pilots.ToManyRelationships[0]) texts := txtsFromToMany(tables, pilots, pilots.ToManyRelationships[0])
expect := TxtToMany{} expect := TxtToMany{}
expect.LocalTable.Name = "pilots"
expect.LocalTable.NameGo = "Pilot" expect.LocalTable.NameGo = "Pilot"
expect.LocalTable.NameSingular = "pilot" expect.LocalTable.NameSingular = "pilot"
expect.LocalTable.ColumnNameGo = "ID" expect.LocalTable.ColumnNameGo = "ID"
expect.ForeignTable.Name = "licenses"
expect.ForeignTable.NameGo = "License" expect.ForeignTable.NameGo = "License"
expect.ForeignTable.NameSingular = "license" expect.ForeignTable.NameSingular = "license"
expect.ForeignTable.NamePluralGo = "Licenses" expect.ForeignTable.NamePluralGo = "Licenses"
@ -161,12 +156,10 @@ func TestTxtsFromMany(t *testing.T) {
texts = txtsFromToMany(tables, pilots, pilots.ToManyRelationships[1]) texts = txtsFromToMany(tables, pilots, pilots.ToManyRelationships[1])
expect = TxtToMany{} expect = TxtToMany{}
expect.LocalTable.Name = "pilots"
expect.LocalTable.NameGo = "Pilot" expect.LocalTable.NameGo = "Pilot"
expect.LocalTable.NameSingular = "pilot" expect.LocalTable.NameSingular = "pilot"
expect.LocalTable.ColumnNameGo = "ID" expect.LocalTable.ColumnNameGo = "ID"
expect.ForeignTable.Name = "languages"
expect.ForeignTable.NameGo = "Language" expect.ForeignTable.NameGo = "Language"
expect.ForeignTable.NameSingular = "language" expect.ForeignTable.NameSingular = "language"
expect.ForeignTable.NamePluralGo = "Languages" expect.ForeignTable.NamePluralGo = "Languages"