@@ -225,13 +225,17 @@ export class ExpressionTransformer<Schema extends SchemaDef> {
225225 let normalizedLeft : Expression = expr . left ;
226226 if ( this . isRelationField ( expr . left , context . model ) ) {
227227 invariant ( ExpressionUtils . isNull ( expr . right ) , 'only null comparison is supported for relation field' ) ;
228- const idFields = requireIdFields ( this . schema , context . model ) ;
228+ const leftRelDef = this . getFieldDefFromFieldRef ( expr . left , context . model ) ;
229+ invariant ( leftRelDef , 'failed to get relation field definition' ) ;
230+ const idFields = requireIdFields ( this . schema , leftRelDef . type ) ;
229231 normalizedLeft = this . makeOrAppendMember ( normalizedLeft , idFields [ 0 ] ! ) ;
230232 }
231233 let normalizedRight : Expression = expr . right ;
232234 if ( this . isRelationField ( expr . right , context . model ) ) {
233235 invariant ( ExpressionUtils . isNull ( expr . left ) , 'only null comparison is supported for relation field' ) ;
234- const idFields = requireIdFields ( this . schema , context . model ) ;
236+ const rightRelDef = this . getFieldDefFromFieldRef ( expr . right , context . model ) ;
237+ invariant ( rightRelDef , 'failed to get relation field definition' ) ;
238+ const idFields = requireIdFields ( this . schema , rightRelDef . type ) ;
235239 normalizedRight = this . makeOrAppendMember ( normalizedRight , idFields [ 0 ] ! ) ;
236240 }
237241 return { normalizedLeft, normalizedRight } ;
0 commit comments