@@ -25,10 +25,10 @@ export async function generateModelString(
25
25
26
26
let fieldString = ''
27
27
let getFields = ''
28
- let constructorFields = ''
28
+ // const constructorFields = ''
29
29
let jsonFields = '{\n'
30
30
let jsonRelations = ''
31
- let declareFields = ''
31
+ // let declareFields = ''
32
32
let uuidQuery = ''
33
33
let whereStatements = ''
34
34
let whereFunctionStatements = ''
@@ -166,11 +166,11 @@ export async function generateModelString(
166
166
if ( relationType === 'hasType' && relationCount === 'many' ) {
167
167
const relationName = camelCase ( relation . relationName || tableRelation )
168
168
169
- declareFields += `public ${ snakeCase ( relationName ) } : ${ modelRelation } Model[] | undefined\n`
169
+ // declareFields += `public ${snakeCase(relationName)}: ${modelRelation}Model[] | undefined\n`
170
170
getFields += `get ${ snakeCase ( relationName ) } ():${ modelRelation } Model[] | undefined {
171
171
return this.attributes.${ snakeCase ( relationName ) }
172
- }`
173
- constructorFields += `this.${ snakeCase ( relationName ) } = ${ formattedModelName } ?.${ snakeCase ( relationName ) } \n`
172
+ }\n\n `
173
+ // constructorFields += `this.${snakeCase(relationName)} = ${formattedModelName}?.${snakeCase(relationName)}\n`
174
174
fieldString += `${ snakeCase ( relationName ) } ?: ${ modelRelation } Model[] | undefined\n`
175
175
176
176
relationStringThisMany += `
@@ -216,22 +216,22 @@ export async function generateModelString(
216
216
const relationName = camelCase ( relation . relationName || formattedModelRelation )
217
217
218
218
fieldString += ` ${ relation . modelKey } ?: number \n`
219
- declareFields += `public ${ relation . modelKey } : number | undefined \n `
219
+ // declareFields += `public ${relation.modelKey}: number | undefined \n `
220
220
221
221
getFields += `get ${ relation . modelKey } (): number | undefined {
222
222
return this.attributes.${ relation . modelKey }
223
- }`
223
+ }\n\n `
224
224
225
- constructorFields += `this.${ relation . modelKey } = ${ formattedModelName } ?.${ relation . modelKey } \n `
225
+ // constructorFields += `this.${relation.modelKey} = ${formattedModelName}?.${relation.modelKey}\n `
226
226
jsonRelations += `${ relation . modelKey } : this.${ relation . modelKey } ,\n `
227
227
228
- declareFields += `public ${ snakeCase ( relationName ) } : ${ modelRelation } Model | undefined\n`
228
+ // declareFields += `public ${snakeCase(relationName)}: ${modelRelation}Model | undefined\n`
229
229
230
230
getFields += `get ${ snakeCase ( relationName ) } (): ${ modelRelation } Model | undefined {
231
231
return this.attributes.${ snakeCase ( relationName ) }
232
- }`
232
+ }\n\n `
233
233
234
- constructorFields += `this.${ snakeCase ( relationName ) } = ${ formattedModelName } ?.${ snakeCase ( relationName ) } \n`
234
+ // constructorFields += `this.${snakeCase(relationName)} = ${formattedModelName}?.${snakeCase(relationName)}\n`
235
235
fieldString += `${ snakeCase ( relationName ) } ?: ${ modelRelation } Model\n`
236
236
237
237
relationStringThisBelong += `
@@ -284,13 +284,13 @@ export async function generateModelString(
284
284
}
285
285
}
286
286
287
- declareFields += `public id: number | undefined \n `
287
+ // declareFields += `public id: number | undefined \n `
288
288
289
289
getFields += `get id(): number | undefined {
290
290
return this.attributes.id
291
- }`
291
+ }\n\n `
292
292
293
- constructorFields += `this.id = ${ formattedModelName } ?.id || 1\n `
293
+ // constructorFields += `this.id = ${formattedModelName}?.id || 1\n `
294
294
295
295
const useTwoFactor = typeof model . traits ?. useAuth === 'object' && model . traits . useAuth . useTwoFactor
296
296
const usePasskey = typeof model . traits ?. useAuth === 'object' && model . traits . useAuth . usePasskey
@@ -560,23 +560,23 @@ export async function generateModelString(
560
560
}
561
561
`
562
562
563
- declareFields += `public stripe_id: string | undefined\n`
563
+ // declareFields += `public stripe_id: string | undefined\n`
564
564
565
565
getFields += `get stripe_id(): string | undefined {
566
566
return this.attributes.stripe_id
567
- }`
567
+ }\n\n `
568
568
569
- constructorFields += `this.stripe_id = ${ formattedModelName } ?.stripe_id\n `
569
+ // constructorFields += `this.stripe_id = ${formattedModelName}?.stripe_id\n `
570
570
}
571
571
572
572
if ( useTwoFactor ) {
573
- declareFields += `public two_factor_secret: string | undefined \n`
573
+ // declareFields += `public two_factor_secret: string | undefined \n`
574
574
575
575
getFields += `get two_factor_secret(): string | undefined {
576
576
return this.attributes.two_factor_secret
577
- }`
577
+ }\n\n `
578
578
579
- constructorFields += `this.two_factor_secret = ${ formattedModelName } ?.two_factor_secret\n `
579
+ // constructorFields += `this.two_factor_secret = ${formattedModelName}?.two_factor_secret\n `
580
580
581
581
twoFactorStatements += `
582
582
async generateTwoFactorForModel() {
@@ -599,31 +599,31 @@ export async function generateModelString(
599
599
}
600
600
601
601
if ( useUuid ) {
602
- declareFields += 'public uuid: string | undefined \n'
602
+ // declareFields += 'public uuid: string | undefined \n'
603
603
getFields += `get uuid(): string | undefined {
604
604
return this.attributes.uuid
605
- }`
606
- constructorFields += `this.uuid = ${ formattedModelName } ?.uuid\n `
605
+ }\n\n `
606
+ // constructorFields += `this.uuid = ${formattedModelName}?.uuid\n `
607
607
}
608
608
609
609
if ( usePasskey ) {
610
- declareFields += 'public public_passkey: string | undefined \n'
610
+ // declareFields += 'public public_passkey: string | undefined \n'
611
611
getFields += `get public_passkey(): string | undefined {
612
612
return this.attributes.public_passkey
613
- }`
614
- constructorFields += `this.public_passkey = ${ formattedModelName } ?.public_passkey\n `
613
+ }\n\n `
614
+ // constructorFields += `this.public_passkey = ${formattedModelName}?.public_passkey\n `
615
615
}
616
616
617
617
jsonFields += '\nid: this.id,\n'
618
618
for ( const attribute of attributes ) {
619
619
const entity = mapEntity ( attribute )
620
620
621
621
fieldString += ` ${ snakeCase ( attribute . field ) } ?: ${ entity } \n `
622
- declareFields += `public ${ snakeCase ( attribute . field ) } : ${ entity } | undefined \n `
622
+ // declareFields += `public ${snakeCase(attribute.field)}: ${entity} | undefined \n `
623
623
getFields += `get ${ snakeCase ( attribute . field ) } (): ${ entity } | undefined {
624
624
return this.attributes.${ snakeCase ( attribute . field ) }
625
- }`
626
- constructorFields += `this.${ snakeCase ( attribute . field ) } = ${ formattedModelName } ?.${ snakeCase ( attribute . field ) } \n `
625
+ }\n\n `
626
+ // constructorFields += `this.${snakeCase(attribute.field)} = ${formattedModelName}?.${snakeCase(attribute.field)}\n `
627
627
jsonFields += `${ snakeCase ( attribute . field ) } : this.${ snakeCase ( attribute . field ) } ,\n `
628
628
629
629
whereStatements += `static where${ pascalCase ( attribute . field ) } (value: string): ${ modelName } Model {
@@ -643,10 +643,10 @@ export async function generateModelString(
643
643
}
644
644
645
645
if ( useTimestamps ) {
646
- declareFields += `
647
- public created_at: Date | undefined
648
- public updated_at: Date | undefined
649
- `
646
+ // declareFields += `
647
+ // public created_at: Date | undefined
648
+ // public updated_at: Date | undefined
649
+ // `
650
650
651
651
getFields += `get created_at(): Date | undefined {
652
652
return this.attributes.created_at
@@ -656,10 +656,10 @@ export async function generateModelString(
656
656
return this.attributes.updated_at
657
657
}`
658
658
659
- constructorFields += `
660
- this.created_at = ${ formattedModelName } ?.created_at\n
661
- this.updated_at = ${ formattedModelName } ?.updated_at\n
662
- `
659
+ // constructorFields += `
660
+ // this.created_at = ${formattedModelName}?.created_at\n
661
+ // this.updated_at = ${formattedModelName}?.updated_at\n
662
+ // `
663
663
664
664
jsonFields += `
665
665
created_at: this.created_at,\n
@@ -668,16 +668,16 @@ export async function generateModelString(
668
668
}
669
669
670
670
if ( useSoftDeletes ) {
671
- declareFields += `
672
- public deleted_at: Date | undefined
673
- `
671
+ // declareFields += `
672
+ // public deleted_at: Date | undefined
673
+ // `
674
674
getFields += `get deleted_at(): Date | undefined {
675
675
return this.attributes.deleted_at
676
- }`
676
+ }\n\n `
677
677
678
- constructorFields += `
679
- this.deleted_at = ${ formattedModelName } ?.deleted_at\n
680
- `
678
+ // constructorFields += `
679
+ // this.deleted_at = ${formattedModelName}?.deleted_at\n
680
+ // `
681
681
682
682
jsonFields += `
683
683
deleted_at: this.deleted_at,\n
@@ -770,17 +770,17 @@ export async function generateModelString(
770
770
private readonly hidden: Array<keyof ${ modelName } JsonResponse> = ${ hidden }
771
771
private readonly fillable: Array<keyof ${ modelName } JsonResponse> = ${ fillable }
772
772
private readonly guarded: Array<keyof ${ modelName } JsonResponse> = ${ guarded }
773
+ protected attributes: Partial<UserType> = {}
774
+ protected originalAttributes: Partial<UserType> = {}
773
775
${ privateSoftDeletes }
774
776
protected selectFromQuery: any
775
777
protected withRelations: string[]
776
778
protected updateFromQuery: any
777
779
protected deleteFromQuery: any
778
780
protected hasSelect: boolean
779
781
private customColumns: Record<string, unknown> = {}
780
- ${ declareFields }
781
782
constructor(${ formattedModelName } : Partial<${ modelName } Type> | null) {
782
783
if (${ formattedModelName } ) {
783
- ${ constructorFields }
784
784
785
785
Object.keys(${ formattedModelName } ).forEach(key => {
786
786
if (!(key in this)) {
@@ -795,6 +795,8 @@ export async function generateModelString(
795
795
this.deleteFromQuery = DB.instance.deleteFrom('${ tableName } ')
796
796
this.hasSelect = false
797
797
}
798
+
799
+ ${ getFields }
798
800
799
801
select(params: (keyof ${ modelName } Type)[] | RawBuilder<string> | string): ${ modelName } Model {
800
802
return ${ modelName } Model.select(params)
0 commit comments