Skip to content

Commit d9b1abf

Browse files
committed
update
1 parent b2ce74c commit d9b1abf

File tree

1 file changed

+6
-8
lines changed

1 file changed

+6
-8
lines changed

packages/runtime/src/client/crud/dialects/base-dialect.ts

Lines changed: 6 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -931,14 +931,12 @@ export abstract class BaseCrudDialect<Schema extends SchemaDef> {
931931
): SelectQueryBuilder<any, any, any> {
932932
const fieldDef = requireField(this.schema, model, field);
933933

934-
if (!fieldDef.originModel) {
935-
// field defined on this model
936-
return query.select(() => this.fieldRef(model, field, modelAlias).as(field));
937-
} else {
938-
// field defined on a delegate base, build a select with the origin model
939-
// name (the model is already joined from outer query)
940-
return this.buildSelectField(query, fieldDef.originModel, fieldDef.originModel, field);
941-
}
934+
// if field is defined on a delegate base, the base model is joined with its
935+
// model name from outer query, so we should use it directly as the alias
936+
const fieldModel = fieldDef.originModel ?? model;
937+
const alias = fieldDef.originModel ?? modelAlias;
938+
939+
return query.select(() => this.fieldRef(fieldModel, field, alias).as(field));
942940
}
943941

944942
buildDelegateJoin(

0 commit comments

Comments
 (0)