Skip to content

Commit 841b0ed

Browse files
authored
fix(policy): relation field resolution issue (#263)
1 parent f9baaaf commit 841b0ed

File tree

1 file changed

+6
-2
lines changed

1 file changed

+6
-2
lines changed

packages/runtime/src/plugins/policy/expression-transformer.ts

Lines changed: 6 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -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

Comments
 (0)