2016-06-23 07:03:05 +02:00
{ { - if . Table . IsJoinTable - } }
{ { - else - } }
2016-09-14 10:08:30 +02:00
{ { - $dot : = . - } }
{ { - $table : = . Table - } }
{ { - range . Table . ToManyRelationships - } }
{ { - $varNameSingular : = . ForeignTable | singular | camelCase - } }
2016-09-23 06:47:50 +02:00
{ { - $txt : = txtsFromToMany $dot.Tables $table . - } }
2016-09-24 09:52:18 +02:00
{ { - $schemaForeignTable : = . ForeignTable | $dot.SchemaTable } }
2016-09-23 06:47:50 +02:00
// { { $txt.Function.Name } } G retrieves all the { { . ForeignTable | singular } } 's { { $txt.ForeignTable.NameHumanReadable } }
{ { - if not ( eq $txt.Function.Name $txt.ForeignTable.NamePluralGo ) } } via { { . ForeignColumn } } column { { - end } } .
func (o * { { $txt.LocalTable.NameGo } } ) { { $txt.Function.Name } } G(mods ...qm.QueryMod) { { $varNameSingular } } Query {
return o. { { $txt.Function.Name } } (boil.GetDB(), mods...)
2016-07-12 00:23:47 +02:00
}
2016-09-23 06:47:50 +02:00
// { { $txt.Function.Name } } retrieves all the { { . ForeignTable | singular } } 's { { $txt.ForeignTable.NameHumanReadable } } with an executor
{ { - if not ( eq $txt.Function.Name $txt.ForeignTable.NamePluralGo ) } } via { { . ForeignColumn } } column { { - end } } .
func (o * { { $txt.LocalTable.NameGo } } ) { { $txt.Function.Name } } (exec boil.Executor, mods ...qm.QueryMod) { { $varNameSingular } } Query {
2017-06-15 05:53:39 +02:00
var queryMods []qm.QueryMod
2016-09-14 10:08:30 +02:00
if len(mods) != 0 {
queryMods = append(queryMods, mods...)
}
2016-08-04 07:36:08 +02:00
2016-09-14 10:08:30 +02:00
{ { if . ToJoinTable - } }
queryMods = append(queryMods,
2017-06-04 21:29:04 +02:00
{ { $schemaJoinTable : = . JoinTable | $ . SchemaTable - } }
qm.InnerJoin(" { { $schemaJoinTable } } on { { $schemaForeignTable } } . { { . ForeignColumn | $dot.Quotes } } = { { $schemaJoinTable } } . { { . JoinForeignColumn | $dot.Quotes } } "),
qm.Where(" { { $schemaJoinTable } } . { { . JoinLocalColumn | $dot.Quotes } } =?", o. { { $txt.LocalTable.ColumnNameGo } } ),
2016-09-14 10:08:30 +02:00
)
{ { else - } }
queryMods = append(queryMods,
2017-06-04 21:29:04 +02:00
qm.Where(" { { $schemaForeignTable } } . { { . ForeignColumn | $dot.Quotes } } =?", o. { { $txt.LocalTable.ColumnNameGo } } ),
2016-09-14 10:08:30 +02:00
)
{ { end } }
2016-06-27 01:18:23 +02:00
2016-09-23 06:47:50 +02:00
query := { { $txt.ForeignTable.NamePluralGo } } (exec, queryMods...)
2017-06-04 21:29:04 +02:00
queries.SetFrom(query.Query, " { { $schemaForeignTable } } ")
2017-06-15 05:53:39 +02:00
if len(queries.GetSelect(query.Query)) == 0 {
queries.SetSelect(query.Query, []string { "{{$schemaForeignTable}}.*" } )
}
2016-09-14 10:08:30 +02:00
return query
2016-06-27 01:18:23 +02:00
}
2016-07-16 13:22:57 +02:00
2016-09-18 08:50:31 +02:00
{ { end - } } { { - / * range relationships * / - } }
2016-09-09 14:31:51 +02:00
{ { - end - } } { { - / * if isJoinTable * / - } }