File tree Expand file tree Collapse file tree 19 files changed +70
-72
lines changed Expand file tree Collapse file tree 19 files changed +70
-72
lines changed Original file line number Diff line number Diff line change @@ -10,7 +10,7 @@ export default new Action({
10
10
async handle ( request : UserRequestType ) {
11
11
// const id = request.getParam('id')
12
12
13
- const result = await User . get ( )
13
+ const result = await User . with ( [ 'posts' ] ) . get ( )
14
14
15
15
return response . json ( result )
16
16
} ,
Original file line number Diff line number Diff line change @@ -1911,7 +1911,7 @@ export async function generateModelString(
1911
1911
}
1912
1912
}
1913
1913
1914
- async loadRelationsHasMany(models: UserModel []): Promise<void> {
1914
+ async loadRelationsHasMany(models: ${ modelName } Model []): Promise<void> {
1915
1915
if (!models.length)
1916
1916
return
1917
1917
@@ -1920,16 +1920,16 @@ export async function generateModelString(
1920
1920
for (const relation of this.withRelations) {
1921
1921
const relatedRecords = await DB.instance
1922
1922
.selectFrom(relation)
1923
- .where('user_id ', 'in', modelIds)
1923
+ .where('${ formattedModelName } _id ', 'in', modelIds)
1924
1924
.selectAll()
1925
1925
.execute()
1926
1926
1927
- models.map((model: UserModel ) => {
1927
+ models.map((model: ${ modelName } Model ) => {
1928
1928
const records = relatedRecords.filter((record: any) => {
1929
1929
return record.${ formattedModelName } _id === model.id
1930
1930
})
1931
1931
1932
- model[relation] = records
1932
+ model[relation] = records.length === 1 ? records[0] : records
1933
1933
1934
1934
return model
1935
1935
})
Original file line number Diff line number Diff line change @@ -1165,7 +1165,7 @@ export class AccessTokenModel {
1165
1165
}
1166
1166
}
1167
1167
1168
- async loadRelationsHasMany ( models : UserModel [ ] ) : Promise < void > {
1168
+ async loadRelationsHasMany ( models : AccessTokenModel [ ] ) : Promise < void > {
1169
1169
if ( ! models . length )
1170
1170
return
1171
1171
@@ -1174,16 +1174,16 @@ export class AccessTokenModel {
1174
1174
for ( const relation of this . withRelations ) {
1175
1175
const relatedRecords = await DB . instance
1176
1176
. selectFrom ( relation )
1177
- . where ( 'user_id ' , 'in' , modelIds )
1177
+ . where ( 'accesstoken_id ' , 'in' , modelIds )
1178
1178
. selectAll ( )
1179
1179
. execute ( )
1180
1180
1181
- models . map ( ( model : UserModel ) => {
1181
+ models . map ( ( model : AccessTokenModel ) => {
1182
1182
const records = relatedRecords . filter ( ( record : any ) => {
1183
1183
return record . accesstoken_id === model . id
1184
1184
} )
1185
1185
1186
- model [ relation ] = records
1186
+ model [ relation ] = records . length === 1 ? records [ 0 ] : records
1187
1187
1188
1188
return model
1189
1189
} )
Original file line number Diff line number Diff line change @@ -1215,7 +1215,7 @@ export class ActivityModel {
1215
1215
}
1216
1216
}
1217
1217
1218
- async loadRelationsHasMany ( models : UserModel [ ] ) : Promise < void > {
1218
+ async loadRelationsHasMany ( models : ActivityModel [ ] ) : Promise < void > {
1219
1219
if ( ! models . length )
1220
1220
return
1221
1221
@@ -1224,16 +1224,16 @@ export class ActivityModel {
1224
1224
for ( const relation of this . withRelations ) {
1225
1225
const relatedRecords = await DB . instance
1226
1226
. selectFrom ( relation )
1227
- . where ( 'user_id ' , 'in' , modelIds )
1227
+ . where ( 'activity_id ' , 'in' , modelIds )
1228
1228
. selectAll ( )
1229
1229
. execute ( )
1230
1230
1231
- models . map ( ( model : UserModel ) => {
1231
+ models . map ( ( model : ActivityModel ) => {
1232
1232
const records = relatedRecords . filter ( ( record : any ) => {
1233
1233
return record . activity_id === model . id
1234
1234
} )
1235
1235
1236
- model [ relation ] = records
1236
+ model [ relation ] = records . length === 1 ? records [ 0 ] : records
1237
1237
1238
1238
return model
1239
1239
} )
Original file line number Diff line number Diff line change @@ -1230,7 +1230,7 @@ export class DeploymentModel {
1230
1230
}
1231
1231
}
1232
1232
1233
- async loadRelationsHasMany ( models : UserModel [ ] ) : Promise < void > {
1233
+ async loadRelationsHasMany ( models : DeploymentModel [ ] ) : Promise < void > {
1234
1234
if ( ! models . length )
1235
1235
return
1236
1236
@@ -1239,16 +1239,16 @@ export class DeploymentModel {
1239
1239
for ( const relation of this . withRelations ) {
1240
1240
const relatedRecords = await DB . instance
1241
1241
. selectFrom ( relation )
1242
- . where ( 'user_id ' , 'in' , modelIds )
1242
+ . where ( 'deployment_id ' , 'in' , modelIds )
1243
1243
. selectAll ( )
1244
1244
. execute ( )
1245
1245
1246
- models . map ( ( model : UserModel ) => {
1246
+ models . map ( ( model : DeploymentModel ) => {
1247
1247
const records = relatedRecords . filter ( ( record : any ) => {
1248
1248
return record . deployment_id === model . id
1249
1249
} )
1250
1250
1251
- model [ relation ] = records
1251
+ model [ relation ] = records . length === 1 ? records [ 0 ] : records
1252
1252
1253
1253
return model
1254
1254
} )
Original file line number Diff line number Diff line change @@ -1169,7 +1169,7 @@ export class ErrorModel {
1169
1169
}
1170
1170
}
1171
1171
1172
- async loadRelationsHasMany ( models : UserModel [ ] ) : Promise < void > {
1172
+ async loadRelationsHasMany ( models : ErrorModel [ ] ) : Promise < void > {
1173
1173
if ( ! models . length )
1174
1174
return
1175
1175
@@ -1178,16 +1178,16 @@ export class ErrorModel {
1178
1178
for ( const relation of this . withRelations ) {
1179
1179
const relatedRecords = await DB . instance
1180
1180
. selectFrom ( relation )
1181
- . where ( 'user_id ' , 'in' , modelIds )
1181
+ . where ( 'error_id ' , 'in' , modelIds )
1182
1182
. selectAll ( )
1183
1183
. execute ( )
1184
1184
1185
- models . map ( ( model : UserModel ) => {
1185
+ models . map ( ( model : ErrorModel ) => {
1186
1186
const records = relatedRecords . filter ( ( record : any ) => {
1187
1187
return record . error_id === model . id
1188
1188
} )
1189
1189
1190
- model [ relation ] = records
1190
+ model [ relation ] = records . length === 1 ? records [ 0 ] : records
1191
1191
1192
1192
return model
1193
1193
} )
Original file line number Diff line number Diff line change @@ -1169,7 +1169,7 @@ export class FailedJobModel {
1169
1169
}
1170
1170
}
1171
1171
1172
- async loadRelationsHasMany ( models : UserModel [ ] ) : Promise < void > {
1172
+ async loadRelationsHasMany ( models : FailedJobModel [ ] ) : Promise < void > {
1173
1173
if ( ! models . length )
1174
1174
return
1175
1175
@@ -1178,16 +1178,16 @@ export class FailedJobModel {
1178
1178
for ( const relation of this . withRelations ) {
1179
1179
const relatedRecords = await DB . instance
1180
1180
. selectFrom ( relation )
1181
- . where ( 'user_id ' , 'in' , modelIds )
1181
+ . where ( 'failedjob_id ' , 'in' , modelIds )
1182
1182
. selectAll ( )
1183
1183
. execute ( )
1184
1184
1185
- models . map ( ( model : UserModel ) => {
1185
+ models . map ( ( model : FailedJobModel ) => {
1186
1186
const records = relatedRecords . filter ( ( record : any ) => {
1187
1187
return record . failedjob_id === model . id
1188
1188
} )
1189
1189
1190
- model [ relation ] = records
1190
+ model [ relation ] = records . length === 1 ? records [ 0 ] : records
1191
1191
1192
1192
return model
1193
1193
} )
Original file line number Diff line number Diff line change @@ -1169,7 +1169,7 @@ export class JobModel {
1169
1169
}
1170
1170
}
1171
1171
1172
- async loadRelationsHasMany ( models : UserModel [ ] ) : Promise < void > {
1172
+ async loadRelationsHasMany ( models : JobModel [ ] ) : Promise < void > {
1173
1173
if ( ! models . length )
1174
1174
return
1175
1175
@@ -1178,16 +1178,16 @@ export class JobModel {
1178
1178
for ( const relation of this . withRelations ) {
1179
1179
const relatedRecords = await DB . instance
1180
1180
. selectFrom ( relation )
1181
- . where ( 'user_id ' , 'in' , modelIds )
1181
+ . where ( 'job_id ' , 'in' , modelIds )
1182
1182
. selectAll ( )
1183
1183
. execute ( )
1184
1184
1185
- models . map ( ( model : UserModel ) => {
1185
+ models . map ( ( model : JobModel ) => {
1186
1186
const records = relatedRecords . filter ( ( record : any ) => {
1187
1187
return record . job_id === model . id
1188
1188
} )
1189
1189
1190
- model [ relation ] = records
1190
+ model [ relation ] = records . length === 1 ? records [ 0 ] : records
1191
1191
1192
1192
return model
1193
1193
} )
Original file line number Diff line number Diff line change @@ -1239,7 +1239,7 @@ export class PaymentMethodModel {
1239
1239
}
1240
1240
}
1241
1241
1242
- async loadRelationsHasMany ( models : UserModel [ ] ) : Promise < void > {
1242
+ async loadRelationsHasMany ( models : PaymentMethodModel [ ] ) : Promise < void > {
1243
1243
if ( ! models . length )
1244
1244
return
1245
1245
@@ -1248,16 +1248,16 @@ export class PaymentMethodModel {
1248
1248
for ( const relation of this . withRelations ) {
1249
1249
const relatedRecords = await DB . instance
1250
1250
. selectFrom ( relation )
1251
- . where ( 'user_id ' , 'in' , modelIds )
1251
+ . where ( 'paymentmethod_id ' , 'in' , modelIds )
1252
1252
. selectAll ( )
1253
1253
. execute ( )
1254
1254
1255
- models . map ( ( model : UserModel ) => {
1255
+ models . map ( ( model : PaymentMethodModel ) => {
1256
1256
const records = relatedRecords . filter ( ( record : any ) => {
1257
1257
return record . paymentmethod_id === model . id
1258
1258
} )
1259
1259
1260
- model [ relation ] = records
1260
+ model [ relation ] = records . length === 1 ? records [ 0 ] : records
1261
1261
1262
1262
return model
1263
1263
} )
Original file line number Diff line number Diff line change @@ -1131,7 +1131,7 @@ export class PostModel {
1131
1131
}
1132
1132
}
1133
1133
1134
- async loadRelationsHasMany ( models : UserModel [ ] ) : Promise < void > {
1134
+ async loadRelationsHasMany ( models : PostModel [ ] ) : Promise < void > {
1135
1135
if ( ! models . length )
1136
1136
return
1137
1137
@@ -1140,16 +1140,16 @@ export class PostModel {
1140
1140
for ( const relation of this . withRelations ) {
1141
1141
const relatedRecords = await DB . instance
1142
1142
. selectFrom ( relation )
1143
- . where ( 'user_id ' , 'in' , modelIds )
1143
+ . where ( 'post_id ' , 'in' , modelIds )
1144
1144
. selectAll ( )
1145
1145
. execute ( )
1146
1146
1147
- models . map ( ( model : UserModel ) => {
1147
+ models . map ( ( model : PostModel ) => {
1148
1148
const records = relatedRecords . filter ( ( record : any ) => {
1149
1149
return record . post_id === model . id
1150
1150
} )
1151
1151
1152
- model [ relation ] = records
1152
+ model [ relation ] = records . length === 1 ? records [ 0 ] : records
1153
1153
1154
1154
return model
1155
1155
} )
You can’t perform that action at this time.
0 commit comments