@@ -308,19 +308,13 @@ export class Processor {
308
308
record : { id, type } ,
309
309
relationship
310
310
} = expression ;
311
- const qb = this . queryForType ( trx , type ) . mergeContext ( {
311
+
312
+ let qb = this . queryForType ( trx , type ) . mergeContext ( {
312
313
recordId : id
313
314
} ) ;
314
- const { model : relatedType } = this . schema . getRelationship (
315
- type ,
316
- relationship
317
- ) ;
318
-
319
315
const parent = ( await qb . findById ( id ) ) as BaseModel ;
320
- const query = await parent
321
- . $relatedQuery < BaseModel > ( relationship , trx )
322
- . select ( this . fieldsForType ( relatedType as string ) ) ;
323
- const model = ( ( await query ) as any ) as ( BaseModel | undefined ) ;
316
+ qb = this . queryForRelationship ( trx , parent , relationship ) ;
317
+ const model = ( ( await qb ) as any ) as ( BaseModel | undefined ) ;
324
318
325
319
return model ? model . toOrbitRecord ( ) : null ;
326
320
}
@@ -333,20 +327,13 @@ export class Processor {
333
327
record : { id, type } ,
334
328
relationship
335
329
} = expression ;
336
- const { model : relatedType } = this . schema . getRelationship (
337
- type ,
338
- relationship
339
- ) ;
340
330
341
331
let qb = this . queryForType ( trx , type ) . mergeContext ( {
342
332
recordId : id
343
333
} ) ;
344
334
const parent = ( await qb . findById ( id ) ) as BaseModel ;
345
- qb = parent
346
- . $relatedQuery < BaseModel > ( relationship , trx )
347
- . select ( this . fieldsForType ( relatedType as string ) ) ;
348
335
const models = ( await this . parseQueryExpression (
349
- qb ,
336
+ this . queryForRelationship ( trx , parent , relationship ) ,
350
337
expression
351
338
) ) as BaseModel [ ] ;
352
339
@@ -372,6 +359,20 @@ export class Processor {
372
359
return qb ;
373
360
}
374
361
362
+ queryForRelationship (
363
+ trx : Transaction ,
364
+ model : BaseModel ,
365
+ relationship : string
366
+ ) {
367
+ const { model : relatedType } = this . schema . getRelationship (
368
+ model . orbitType ,
369
+ relationship
370
+ ) ;
371
+ const fields = this . fieldsForType ( relatedType as string ) ;
372
+
373
+ return model . $relatedQuery < BaseModel > ( relationship , trx ) . select ( fields ) ;
374
+ }
375
+
375
376
protected parseQueryExpressionPage (
376
377
qb : QueryBuilder < BaseModel > ,
377
378
expression : FindRecords | FindRelatedRecords
0 commit comments