@@ -1075,7 +1075,7 @@ export async function generateModelString(
1075
1075
jsonFields += `${ snakeCase ( attribute . field ) } : this.${ snakeCase ( attribute . field ) } ,\n `
1076
1076
1077
1077
whereStatements += `static where${ pascalCase ( attribute . field ) } (value: string): ${ modelName } Model {
1078
- const instance = new this (null)
1078
+ const instance = new ${ modelName } Model (null)
1079
1079
1080
1080
instance.query = instance.query.where('${ attribute . field } ', '=', value)
1081
1081
@@ -1227,7 +1227,7 @@ export async function generateModelString(
1227
1227
static async find(id: number): Promise<${ modelName } Model | undefined> {
1228
1228
let query = db.selectFrom('${ tableName } ').where('id', '=', id).selectAll()
1229
1229
1230
- const instance = new this (null)
1230
+ const instance = new ${ modelName } Model (null)
1231
1231
1232
1232
const model = await query.executeTakeFirst()
1233
1233
@@ -1236,13 +1236,13 @@ export async function generateModelString(
1236
1236
1237
1237
cache.getOrSet(\`${ formattedModelName } :\${id}\`, JSON.stringify(model))
1238
1238
1239
- return instance.parseResult(new this (model))
1239
+ return instance.parseResult(new ${ modelName } Model (model))
1240
1240
}
1241
1241
1242
1242
static async all(): Promise<${ modelName } Model[]> {
1243
1243
let query = db.selectFrom('${ tableName } ').selectAll()
1244
1244
1245
- const instance = new this (null)
1245
+ const instance = new ${ modelName } Model (null)
1246
1246
1247
1247
if (instance.softDeletes) {
1248
1248
query = query.where('deleted_at', 'is', null)
@@ -1257,7 +1257,7 @@ export async function generateModelString(
1257
1257
static async findOrFail(id: number): Promise<${ modelName } Model> {
1258
1258
let query = db.selectFrom('${ tableName } ').where('id', '=', id)
1259
1259
1260
- const instance = new this (null)
1260
+ const instance = new ${ modelName } Model (null)
1261
1261
1262
1262
if (instance.softDeletes) {
1263
1263
query = query.where('deleted_at', 'is', null);
@@ -1272,13 +1272,13 @@ export async function generateModelString(
1272
1272
1273
1273
cache.getOrSet(\`${ formattedModelName } :\${id}\`, JSON.stringify(model))
1274
1274
1275
- return instance.parseResult(new this (model))
1275
+ return instance.parseResult(new ${ modelName } Model (model))
1276
1276
}
1277
1277
1278
1278
static async findMany(ids: number[]): Promise<${ modelName } Model[]> {
1279
1279
let query = db.selectFrom('${ tableName } ').where('id', 'in', ids)
1280
1280
1281
- const instance = new this (null)
1281
+ const instance = new ${ modelName } Model (null)
1282
1282
1283
1283
if (instance.softDeletes) {
1284
1284
query = query.where('deleted_at', 'is', null);
@@ -1293,7 +1293,7 @@ export async function generateModelString(
1293
1293
1294
1294
// Method to get a User by criteria
1295
1295
static async get(): Promise<UserModel[]> {
1296
- const instance = new this (null)
1296
+ const instance = new ${ modelName } Model (null)
1297
1297
1298
1298
if (instance.hasSelect) {
1299
1299
if (instance.softDeletes) {
@@ -1338,7 +1338,7 @@ export async function generateModelString(
1338
1338
}
1339
1339
1340
1340
static async count(): Promise<number> {
1341
- const instance = new this (null)
1341
+ const instance = new ${ modelName } Model (null)
1342
1342
1343
1343
if (instance.softDeletes) {
1344
1344
instance.query = instance.query.where('deleted_at', 'is', null);
@@ -1399,7 +1399,7 @@ export async function generateModelString(
1399
1399
1400
1400
// Method to create a new ${ formattedModelName }
1401
1401
static async create(new${ modelName } : New${ modelName } ): Promise<${ modelName } Model> {
1402
- const instance = new this (null)
1402
+ const instance = new ${ modelName } Model (null)
1403
1403
1404
1404
const filteredValues = Object.fromEntries(
1405
1405
Object.entries(new${ modelName } ).filter(([key]) => instance.fillable.includes(key)),
@@ -1430,7 +1430,7 @@ export async function generateModelString(
1430
1430
1431
1431
// Method to remove a ${ modelName }
1432
1432
static async remove(id: number): Promise<void> {
1433
- const instance = new this (null)
1433
+ const instance = new ${ modelName } Model (null)
1434
1434
const model = await instance.find(id)
1435
1435
1436
1436
if (instance.softDeletes) {
@@ -1474,7 +1474,7 @@ export async function generateModelString(
1474
1474
let operator: any
1475
1475
let value: any
1476
1476
1477
- const instance = new this (null)
1477
+ const instance = new ${ modelName } Model (null)
1478
1478
1479
1479
if (args.length === 2) {
1480
1480
[column, value] = args
@@ -1493,7 +1493,7 @@ export async function generateModelString(
1493
1493
${ whereStatements }
1494
1494
1495
1495
static whereIn(column: keyof ${ modelName } Type, values: any[]): ${ modelName } Model {
1496
- const instance = new this (null)
1496
+ const instance = new ${ modelName } Model (null)
1497
1497
1498
1498
instance.query = instance.query.where(column, 'in', values)
1499
1499
@@ -1540,7 +1540,7 @@ export async function generateModelString(
1540
1540
}
1541
1541
1542
1542
static orderBy(column: keyof ${ modelName } Type, order: 'asc' | 'desc'): ${ modelName } Model {
1543
- const instance = new this (null)
1543
+ const instance = new ${ modelName } Model (null)
1544
1544
1545
1545
instance.query = instance.query.orderBy(column, order)
1546
1546
@@ -1554,7 +1554,7 @@ export async function generateModelString(
1554
1554
}
1555
1555
1556
1556
static orderByDesc(column: keyof ${ modelName } Type): ${ modelName } Model {
1557
- const instance = new this (null)
1557
+ const instance = new ${ modelName } Model (null)
1558
1558
1559
1559
instance.query = instance.query.orderBy(column, 'desc')
1560
1560
@@ -1568,7 +1568,7 @@ export async function generateModelString(
1568
1568
}
1569
1569
1570
1570
static orderByAsc(column: keyof ${ modelName } Type): ${ modelName } Model {
1571
- const instance = new this (null)
1571
+ const instance = new ${ modelName } Model (null)
1572
1572
1573
1573
instance.query = instance.query.orderBy(column, 'asc')
1574
1574
@@ -1671,7 +1671,7 @@ export async function generateModelString(
1671
1671
}
1672
1672
1673
1673
static distinct(column: keyof ${ modelName } Type): ${ modelName } Model {
1674
- const instance = new this (null)
1674
+ const instance = new ${ modelName } Model (null)
1675
1675
1676
1676
instance.query = instance.query.select(column).distinct()
1677
1677
@@ -1687,7 +1687,7 @@ export async function generateModelString(
1687
1687
}
1688
1688
1689
1689
static join(table: string, firstCol: string, secondCol: string): ${ modelName } Model {
1690
- const instance = new this (null)
1690
+ const instance = new ${ modelName } Model (null)
1691
1691
1692
1692
instance.query = instance.query.innerJoin(table, firstCol, secondCol)
1693
1693
@@ -1701,9 +1701,6 @@ export async function generateModelString(
1701
1701
toJSON() {
1702
1702
const output: Partial<${ modelName } Type> = ${ jsonFields }
1703
1703
1704
- this.hidden.forEach((attr: string) => {
1705
- if (attr in output) delete (output as Record<string, any>)[attr]
1706
- })
1707
1704
1708
1705
type ${ modelName } = Omit<${ modelName } Type, 'password'>
1709
1706
0 commit comments