Skip to content

Commit 686538e

Browse files
committed
new fix
1 parent 55ae94e commit 686538e

File tree

2 files changed

+7
-5
lines changed

2 files changed

+7
-5
lines changed

packages/schema/src/utils/ast-utils.ts

Lines changed: 6 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -118,10 +118,12 @@ function cloneAst<T extends InheritableNode>(
118118
clone.$container = newContainer;
119119

120120
if (isDataModel(newContainer) && isDataModelField(node)) {
121-
// walk up the hierarchy to find the model where the field is defined (delegate or abstract base)
122-
const allBases = getRecursiveBases(newContainer);
123-
clone.$inheritedFrom = allBases.find((base) => base.fields.some((f) => f.name === node.name));
124-
} else {
121+
// walk up the hierarchy to find the upper-most delegate ancestor that defines the field
122+
const delegateBases = getRecursiveBases(newContainer).filter(isDelegateModel);
123+
clone.$inheritedFrom = delegateBases.findLast((base) => base.fields.some((f) => f.name === node.name));
124+
}
125+
126+
if (!clone.$inheritedFrom) {
125127
clone.$inheritedFrom = node.$inheritedFrom ?? getContainerOfType(node, isDataModel);
126128
}
127129

packages/sdk/src/utils.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -460,7 +460,7 @@ export function isDelegateModel(node: AstNode) {
460460
}
461461

462462
export function isDiscriminatorField(field: DataModelField) {
463-
const model = getInheritedFromDelegate(field) ?? field.$container;
463+
const model = field.$inheritedFrom ?? field.$container;
464464
const delegateAttr = getAttribute(model, '@@delegate');
465465
if (!delegateAttr) {
466466
return false;

0 commit comments

Comments
 (0)