Skip to content

Commit e34c530

Browse files
authored
fix(hooks): include delegate base models when calculating models affected by a mutation (#1121)
1 parent c0a9a02 commit e34c530

File tree

3 files changed

+17
-5
lines changed

3 files changed

+17
-5
lines changed

packages/runtime/src/cross/model-meta.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -118,7 +118,7 @@ export type ModelInfo = {
118118
name: string;
119119

120120
/**
121-
* Base types
121+
* Base types (not including abstract base models).
122122
*/
123123
baseTypes?: string[];
124124

packages/runtime/src/cross/query-analyzer.ts

Lines changed: 16 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -4,6 +4,7 @@ import type { ModelMeta } from './model-meta';
44
import { NestedReadVisitor } from './nested-read-visitor';
55
import { NestedWriteVisitor } from './nested-write-visitor';
66
import type { PrismaWriteActionType } from './types';
7+
import { getModelInfo } from './utils';
78

89
/**
910
* Gets models read (including nested ones) given a query args.
@@ -71,6 +72,11 @@ export async function getMutatedModels(
7172
await visitor.visit(model, operation, mutationArgs);
7273
}
7374

75+
// include delegate base models recursively
76+
result.forEach((m) => {
77+
getBaseRecursively(m, modelMeta, result);
78+
});
79+
7480
return [...result];
7581
}
7682

@@ -92,3 +98,13 @@ function collectDeleteCascades(model: string, modelMeta: ModelMeta, result: Set<
9298
collectDeleteCascades(m, modelMeta, result, visited);
9399
});
94100
}
101+
102+
function getBaseRecursively(model: string, modelMeta: ModelMeta, result: Set<string>) {
103+
const bases = getModelInfo(modelMeta, model)?.baseTypes;
104+
if (bases) {
105+
bases.forEach((base) => {
106+
result.add(base);
107+
getBaseRecursively(base, modelMeta, result);
108+
});
109+
}
110+
}

packages/runtime/src/enhancements/create-enhancement.ts

Lines changed: 0 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,6 @@ import { isDelegateModel, type ModelMeta } from '../cross';
55
import type { AuthUser } from '../types';
66
import { withDefaultAuth } from './default-auth';
77
import { withDelegate } from './delegate';
8-
import { Logger } from './logger';
98
import { withOmit } from './omit';
109
import { withPassword } from './password';
1110
import { withPolicy } from './policy';
@@ -130,9 +129,6 @@ export function createEnhancement<DbClient extends object>(
130129
);
131130
}
132131

133-
const logger = new Logger(prisma);
134-
logger.info(`Enabled ZenStack enhancements: ${options.kinds?.join(', ')}`);
135-
136132
let result = prisma;
137133

138134
if (

0 commit comments

Comments
 (0)