Skip to content

Commit

Permalink
Use a "Many" association for gorm instead of the reverse pointer (for…
Browse files Browse the repository at this point in the history
… the front) #433 - generation
  • Loading branch information
thomaspeugeot committed Oct 17, 2023
1 parent b2a5c69 commit ab99f31
Show file tree
Hide file tree
Showing 3 changed files with 26 additions and 2 deletions.
19 changes: 18 additions & 1 deletion go/angular/ng_file_class_ts.go
Original file line number Diff line number Diff line change
Expand Up @@ -32,6 +32,12 @@ export class {{Structname}}DB {
// insertion point for basic fields declarations{{` + string(rune(NgClassTsInsertionPerStructBasicFieldsDecl)) + `}}
// insertion point for other declarations{{` + string(rune(NgClassTsInsertionPerStructOtherDecls)) + `}}
{{Structname}}PointersEncoding: {{Structname}}PointersEncoding = new {{Structname}}PointersEncoding
}
export class {{Structname}}PointersEncoding {
// insertion point for other declarations{{` + string(rune(NgClassTsInsertionPerStructPointersEncoding)) + `}}
}
`

Expand All @@ -43,6 +49,7 @@ const (
NgClassTsInsertionPerStructImports NgClassTsInsertionPoint = iota
NgClassTsInsertionPerStructBasicFieldsDecl
NgClassTsInsertionPerStructOtherDecls
NgClassTsInsertionPerStructPointersEncoding
NgClassTsInsertionsNb
)

Expand All @@ -60,6 +67,8 @@ const (

NgClassTSSliceOfPtrToStructFieldsDecl

NgClassPointersEncodingTSSliceOfPtrToStructFieldsDecl

NgClassTSSliceOfPtrToGongStructReverseID

NgClassTSOtherDeclsTimeDuration
Expand All @@ -84,7 +93,10 @@ import { {{AssocStructName}}DB } from './{{assocStructName}}-db'`,
`,

NgClassTSSliceOfPtrToStructFieldsDecl: `
{{FieldName}}?: Array<{{TypeInput}}DB>`,
{{FieldName}}: Array<{{TypeInput}}DB> = []`,

NgClassPointersEncodingTSSliceOfPtrToStructFieldsDecl: `
{{FieldName}}: number[] = []`,

NgClassTSSliceOfPtrToGongStructReverseID: `
{{AssocStructName}}_{{FieldName}}DBID: NullInt64 = new NullInt64
Expand Down Expand Up @@ -210,6 +222,11 @@ func MultiCodeGeneratorNgClass(
"{{FieldName}}", field.Name,
"{{TypeInput}}", field.GongStruct.Name)

TSinsertions[NgClassTsInsertionPerStructPointersEncoding] +=
models.Replace2(NgClassSubTemplateCode[NgClassPointersEncodingTSSliceOfPtrToStructFieldsDecl],
"{{FieldName}}", field.Name,
"{{TypeInput}}", field.GongStruct.Name)

}
}

Expand Down
3 changes: 2 additions & 1 deletion test2/ng/projects/test2/src/lib/a-db.ts
Original file line number Diff line number Diff line change
Expand Up @@ -22,5 +22,6 @@ export class ADB {
}

export class APointersEncoding {
// insertion point for other declarations
Bs: number[] = []
}
}
6 changes: 6 additions & 0 deletions test2/ng/projects/test2/src/lib/b-db.ts
Original file line number Diff line number Diff line change
Expand Up @@ -20,4 +20,10 @@ export class BDB {
A_BsDBID_Index: NullInt64 = new NullInt64 // store the index of the b instance in A.Bs
A_Bs_reverse?: ADB


BPointersEncoding: BPointersEncoding = new BPointersEncoding
}

export class BPointersEncoding {
// insertion point for other declarations
}

0 comments on commit ab99f31

Please sign in to comment.