New texts to reverse a "to_many" into "to_one"
This commit is contained in:
parent
423d4b66bf
commit
1513661e15
3 changed files with 73 additions and 5 deletions
|
@ -28,8 +28,9 @@ type RelationshipToOneTexts struct {
|
|||
PackageName string
|
||||
Name string
|
||||
|
||||
Varname string
|
||||
Receiver string
|
||||
Varname string
|
||||
Receiver string
|
||||
ReverseArgs bool
|
||||
|
||||
LocalAssignment string
|
||||
ForeignAssignment string
|
||||
|
@ -72,6 +73,25 @@ func textsFromForeignKey(packageName string, tables []bdb.Table, table bdb.Table
|
|||
return r
|
||||
}
|
||||
|
||||
func textsFromOneToOneRelationship(packageName string, tables []bdb.Table, table bdb.Table, toMany bdb.ToManyRelationship) RelationshipToOneTexts {
|
||||
fkey := bdb.ForeignKey{
|
||||
Name: "none",
|
||||
Column: toMany.Column,
|
||||
Nullable: toMany.Nullable,
|
||||
Unique: toMany.Unique,
|
||||
|
||||
ForeignTable: toMany.ForeignTable,
|
||||
ForeignColumn: toMany.ForeignColumn,
|
||||
ForeignColumnNullable: toMany.ForeignColumnNullable,
|
||||
ForeignColumnUnique: toMany.ForeignColumnUnique,
|
||||
}
|
||||
|
||||
rel := textsFromForeignKey(packageName, tables, table, fkey)
|
||||
rel.Function.Name = strmangle.TitleCase(strmangle.Singular(toMany.ForeignTable))
|
||||
rel.Function.ReverseArgs = true
|
||||
return rel
|
||||
}
|
||||
|
||||
// RelationshipToManyTexts contains text that will be used by templates.
|
||||
type RelationshipToManyTexts struct {
|
||||
LocalTable struct {
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue