2016-06-23 07:03:05 +02:00
{ { - if . Table . IsJoinTable - } }
{ { - else - } }
2016-08-08 17:18:16 +02:00
{ { - $dot : = . - } }
{ { - $table : = . Table - } }
2016-07-16 22:02:09 +02:00
{ { - range . Table . ToManyRelationships - } }
2016-08-14 00:28:54 +02:00
{ { - if ( and . ForeignColumnUnique ( not . ToJoinTable ) ) - } }
2016-07-18 02:50:01 +02:00
{ { - template "relationship_to_one_helper" ( textsFromOneToOneRelationship $dot.PkgName $dot.Tables $table . ) - } }
{ { - else - } }
2016-07-14 05:31:44 +02:00
{ { - $rel : = textsFromRelationship $dot.Tables $table . - } }
2016-08-01 07:10:10 +02:00
// { { $rel.Function.Name } } G retrieves all the { { $rel.LocalTable.NameSingular } } 's { { $rel.ForeignTable.NameHumanReadable } }
2016-07-14 05:31:44 +02:00
{ { - if not ( eq $rel.Function.Name $rel.ForeignTable.NamePluralGo ) } } via { { . ForeignColumn } } column { { - end } } .
2016-08-04 07:36:08 +02:00
func ( { { $rel.Function.Receiver } } * { { $rel.LocalTable.NameGo } } ) { { $rel.Function.Name } } G(mods ...qm.QueryMod) ( { { $rel.ForeignTable.Slice } } , error) {
return { { $rel.Function.Receiver } } . { { $rel.Function.Name } } (boil.GetDB(), mods...)
2016-07-12 00:23:47 +02:00
}
2016-08-01 07:10:10 +02:00
// { { $rel.Function.Name } } GP panics on error. Retrieves all the { { $rel.LocalTable.NameSingular } } 's { { $rel.ForeignTable.NameHumanReadable } }
2016-07-16 13:22:57 +02:00
{ { - if not ( eq $rel.Function.Name $rel.ForeignTable.NamePluralGo ) } } via { { . ForeignColumn } } column { { - end } } .
2016-08-04 07:36:08 +02:00
func ( { { $rel.Function.Receiver } } * { { $rel.LocalTable.NameGo } } ) { { $rel.Function.Name } } GP(mods ...qm.QueryMod) { { $rel.ForeignTable.Slice } } {
2016-08-05 07:03:37 +02:00
slice, err := { { $rel.Function.Receiver } } . { { $rel.Function.Name } } (boil.GetDB(), mods...)
2016-07-16 13:22:57 +02:00
if err != nil {
panic(boil.WrapErr(err))
}
2016-08-05 07:03:37 +02:00
return slice
2016-07-16 13:22:57 +02:00
}
2016-08-01 07:10:10 +02:00
// { { $rel.Function.Name } } P panics on error. Retrieves all the { { $rel.LocalTable.NameSingular } } 's { { $rel.ForeignTable.NameHumanReadable } } with an executor
2016-07-18 02:50:01 +02:00
{ { - if not ( eq $rel.Function.Name $rel.ForeignTable.NamePluralGo ) } } via { { . ForeignColumn } } column { { - end } } .
2016-08-04 07:36:08 +02:00
func ( { { $rel.Function.Receiver } } * { { $rel.LocalTable.NameGo } } ) { { $rel.Function.Name } } P(exec boil.Executor, mods ...qm.QueryMod) { { $rel.ForeignTable.Slice } } {
2016-08-05 07:03:37 +02:00
slice, err := { { $rel.Function.Receiver } } . { { $rel.Function.Name } } (exec, mods...)
2016-07-18 02:50:01 +02:00
if err != nil {
panic(boil.WrapErr(err))
}
2016-08-05 07:03:37 +02:00
return slice
2016-07-18 02:50:01 +02:00
}
2016-08-01 07:10:10 +02:00
// { { $rel.Function.Name } } retrieves all the { { $rel.LocalTable.NameSingular } } 's { { $rel.ForeignTable.NameHumanReadable } } with an executor
2016-07-14 05:31:44 +02:00
{ { - if not ( eq $rel.Function.Name $rel.ForeignTable.NamePluralGo ) } } via { { . ForeignColumn } } column { { - end } } .
2016-08-04 07:36:08 +02:00
func ( { { $rel.Function.Receiver } } * { { $rel.LocalTable.NameGo } } ) { { $rel.Function.Name } } (exec boil.Executor, mods ...qm.QueryMod) ( { { $rel.ForeignTable.Slice } } , error) {
queryMods := []qm.QueryMod {
qm.Select(`" { { id 0 } } ".*`),
}
2016-06-27 01:18:23 +02:00
2016-08-04 07:36:08 +02:00
if len(mods) != 0 {
queryMods = append(queryMods, mods...)
2016-07-14 05:31:44 +02:00
}
2016-08-04 07:36:08 +02:00
2016-07-02 01:20:59 +02:00
{ { if . ToJoinTable - } }
2016-08-04 07:36:08 +02:00
queryMods = append(queryMods,
qm.InnerJoin(`" { { . JoinTable } } " as " { { id 1 } } " on " { { id 1 } } "." { { . JoinForeignColumn } } " = " { { id 0 } } "." { { . ForeignColumn } } "`),
qm.Where(`" { { id 1 } } "." { { . JoinLocalColumn } } "=$1`, { { . Column | titleCase | printf "%s.%s" $rel.Function.Receiver } } ),
)
2016-07-02 01:20:59 +02:00
{ { else - } }
2016-08-04 07:36:08 +02:00
queryMods = append(queryMods,
qm.Where(`" { { id 0 } } "." { { . ForeignColumn } } "=$1`, { { . Column | titleCase | printf "%s.%s" $rel.Function.Receiver } } ),
)
2016-07-02 01:20:59 +02:00
{ { end } }
2016-06-27 01:18:23 +02:00
2016-08-04 07:36:08 +02:00
query := { { $rel.ForeignTable.NamePluralGo } } (exec, queryMods...)
boil.SetFrom(query.Query, `" { { . ForeignTable } } " as " { { id 0 } } "`)
return query.All()
2016-06-27 01:18:23 +02:00
}
2016-07-16 13:22:57 +02:00
2016-07-18 02:50:01 +02:00
{ { end - } } { { - / * if unique foreign key * / - } }
{ { - end - } } { { - / * range relationships * / - } }
2016-07-02 01:20:59 +02:00
{ { - end - } } { { - / * outer if join table * / - } }