Skip to content

Commit b979a88

Browse files
committed
addressing PR comments
1 parent 21e2585 commit b979a88

File tree

3 files changed

+20
-9
lines changed

3 files changed

+20
-9
lines changed

packages/clients/tanstack-query/src/utils/mutator.ts

Lines changed: 7 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -204,10 +204,14 @@ function createMutate(queryModel: string, currentData: any, newData: any, schema
204204
// default value for DateTime field
205205
if (defaultAttr || field.attributes?.some((attr) => attr.name === '@updatedAt')) {
206206
insert[name] = new Date();
207+
return;
207208
}
208-
} else if (defaultAttr?.args?.[0]?.value !== undefined) {
209+
}
210+
211+
const defaultArg = defaultAttr?.args?.[0]?.value;
212+
if (defaultArg?.kind === 'literal') {
209213
// other default value
210-
insert[name] = defaultAttr.args[0].value;
214+
insert[name] = defaultArg.value;
211215
}
212216
}
213217
});
@@ -425,7 +429,7 @@ function assignForeignKeyFields(field: FieldDef, resultData: any, mutationData:
425429
return;
426430
}
427431

428-
for (const [idField, fkField] of zip(field.relation.fields, field.relation.references)) {
432+
for (const [idField, fkField] of zip(field.relation.references, field.relation.fields)) {
429433
if (idField in mutationData.connect) {
430434
resultData[fkField] = mutationData.connect[idField];
431435
}

packages/clients/tanstack-query/src/utils/nested-write-visitor.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -169,7 +169,7 @@ export class NestedWriteVisitor {
169169

170170
case 'createMany':
171171
case 'createManyAndReturn':
172-
if (data) {
172+
{
173173
const newContext = pushNewContext(field, model, {});
174174
let callbackResult: any;
175175
if (this.callback.createMany) {

packages/clients/tanstack-query/src/utils/query-analysis.ts

Lines changed: 12 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -89,12 +89,19 @@ function collectDeleteCascades(model: string, schema: SchemaDef, result: Set<str
8989
return;
9090
}
9191

92-
Object.values(modelDef.fields).forEach((fieldDef) => {
93-
if (fieldDef.relation && fieldDef.relation.onDelete === 'Cascade') {
94-
result.add(fieldDef.type);
95-
collectDeleteCascades(fieldDef.type, schema, result, visited);
92+
for (const [modelName, modelDef] of Object.entries(schema.models)) {
93+
if (!modelDef) {
94+
continue;
9695
}
97-
});
96+
for (const fieldDef of Object.values(modelDef.fields)) {
97+
if (fieldDef.relation?.onDelete === 'Cascade' && fieldDef.type === model) {
98+
if (!result.has(modelName)) {
99+
result.add(modelName);
100+
}
101+
collectDeleteCascades(modelName, schema, result, visited);
102+
}
103+
}
104+
}
98105
}
99106

100107
function getBaseRecursively(model: string, schema: SchemaDef, result: Set<string>) {

0 commit comments

Comments
 (0)