@@ -24,6 +24,7 @@ export async function generateModelString(
24
24
let thisSoftDeleteStatementsUpdateFrom = ''
25
25
26
26
let fieldString = ''
27
+ let getFields = ''
27
28
let constructorFields = ''
28
29
let jsonFields = '{\n'
29
30
let jsonRelations = ''
@@ -166,6 +167,9 @@ export async function generateModelString(
166
167
const relationName = camelCase ( relation . relationName || tableRelation )
167
168
168
169
declareFields += `public ${ snakeCase ( relationName ) } : ${ modelRelation } Model[] | undefined\n`
170
+ getFields += `get ${ snakeCase ( relationName ) } ():${ modelRelation } Model[] | undefined {
171
+ return this.attributes.${ snakeCase ( relationName ) }
172
+ }`
169
173
constructorFields += `this.${ snakeCase ( relationName ) } = ${ formattedModelName } ?.${ snakeCase ( relationName ) } \n`
170
174
fieldString += `${ snakeCase ( relationName ) } ?: ${ modelRelation } Model[] | undefined\n`
171
175
@@ -213,10 +217,20 @@ export async function generateModelString(
213
217
214
218
fieldString += ` ${ relation . modelKey } ?: number \n`
215
219
declareFields += `public ${ relation . modelKey } : number | undefined \n `
220
+
221
+ getFields += `get ${ relation . modelKey } (): number | undefined {
222
+ return this.attributes.${ relation . modelKey }
223
+ }`
224
+
216
225
constructorFields += `this.${ relation . modelKey } = ${ formattedModelName } ?.${ relation . modelKey } \n `
217
226
jsonRelations += `${ relation . modelKey } : this.${ relation . modelKey } ,\n `
218
227
219
228
declareFields += `public ${ snakeCase ( relationName ) } : ${ modelRelation } Model | undefined\n`
229
+
230
+ getFields += `get ${ snakeCase ( relationName ) } (): ${ modelRelation } Model | undefined {
231
+ return this.attributes.${ snakeCase ( relationName ) }
232
+ }`
233
+
220
234
constructorFields += `this.${ snakeCase ( relationName ) } = ${ formattedModelName } ?.${ snakeCase ( relationName ) } \n`
221
235
fieldString += `${ snakeCase ( relationName ) } ?: ${ modelRelation } Model\n`
222
236
@@ -272,6 +286,10 @@ export async function generateModelString(
272
286
273
287
declareFields += `public id: number | undefined \n `
274
288
289
+ getFields += `get id(): number | undefined {
290
+ return this.attributes.id
291
+ }`
292
+
275
293
constructorFields += `this.id = ${ formattedModelName } ?.id || 1\n `
276
294
277
295
const useTwoFactor = typeof model . traits ?. useAuth === 'object' && model . traits . useAuth . useTwoFactor
@@ -544,11 +562,20 @@ export async function generateModelString(
544
562
545
563
declareFields += `public stripe_id: string | undefined\n`
546
564
565
+ getFields += `get stripe_id(): string | undefined {
566
+ return this.attributes.stripe_id
567
+ }`
568
+
547
569
constructorFields += `this.stripe_id = ${ formattedModelName } ?.stripe_id\n `
548
570
}
549
571
550
572
if ( useTwoFactor ) {
551
573
declareFields += `public two_factor_secret: string | undefined \n`
574
+
575
+ getFields += `get two_factor_secret(): string | undefined {
576
+ return this.attributes.two_factor_secret
577
+ }`
578
+
552
579
constructorFields += `this.two_factor_secret = ${ formattedModelName } ?.two_factor_secret\n `
553
580
554
581
twoFactorStatements += `
@@ -573,11 +600,17 @@ export async function generateModelString(
573
600
574
601
if ( useUuid ) {
575
602
declareFields += 'public uuid: string | undefined \n'
603
+ getFields += `get uuid(): string | undefined {
604
+ return this.attributes.uuid
605
+ }`
576
606
constructorFields += `this.uuid = ${ formattedModelName } ?.uuid\n `
577
607
}
578
608
579
609
if ( usePasskey ) {
580
610
declareFields += 'public public_passkey: string | undefined \n'
611
+ getFields += `get public_passkey(): string | undefined {
612
+ return this.attributes.public_passkey
613
+ }`
581
614
constructorFields += `this.public_passkey = ${ formattedModelName } ?.public_passkey\n `
582
615
}
583
616
@@ -587,6 +620,9 @@ export async function generateModelString(
587
620
588
621
fieldString += ` ${ snakeCase ( attribute . field ) } ?: ${ entity } \n `
589
622
declareFields += `public ${ snakeCase ( attribute . field ) } : ${ entity } | undefined \n `
623
+ getFields += `get ${ snakeCase ( attribute . field ) } (): ${ entity } | undefined {
624
+ return this.attributes.${ snakeCase ( attribute . field ) }
625
+ }`
590
626
constructorFields += `this.${ snakeCase ( attribute . field ) } = ${ formattedModelName } ?.${ snakeCase ( attribute . field ) } \n `
591
627
jsonFields += `${ snakeCase ( attribute . field ) } : this.${ snakeCase ( attribute . field ) } ,\n `
592
628
@@ -612,6 +648,14 @@ export async function generateModelString(
612
648
public updated_at: Date | undefined
613
649
`
614
650
651
+ getFields += `get created_at(): Date | undefined {
652
+ return this.attributes.created_at
653
+ }\n\n
654
+
655
+ get updated_at(): Date | undefined {
656
+ return this.attributes.updated_at
657
+ }`
658
+
615
659
constructorFields += `
616
660
this.created_at = ${ formattedModelName } ?.created_at\n
617
661
this.updated_at = ${ formattedModelName } ?.updated_at\n
@@ -625,8 +669,11 @@ export async function generateModelString(
625
669
626
670
if ( useSoftDeletes ) {
627
671
declareFields += `
628
- public deleted_at: Date | undefined
629
- `
672
+ public deleted_at: Date | undefined
673
+ `
674
+ getFields += `get deleted_at(): Date | undefined {
675
+ return this.attributes.deleted_at
676
+ }`
630
677
631
678
constructorFields += `
632
679
this.deleted_at = ${ formattedModelName } ?.deleted_at\n
0 commit comments