diff --git a/src/lib/createNestedMiddleware.ts b/src/lib/createNestedMiddleware.ts index d2afe6f..a298359 100644 --- a/src/lib/createNestedMiddleware.ts +++ b/src/lib/createNestedMiddleware.ts @@ -12,7 +12,7 @@ if (!Prisma.dmmf) { ); } -const relationsByModel: Record = {}; +export const relationsByModel: Record = {}; Prisma.dmmf.datamodel.models.forEach((model: Prisma.DMMF.Model) => { relationsByModel[model.name] = model.fields.filter( (field) => field.kind === "object" && field.relationName diff --git a/src/lib/types.ts b/src/lib/types.ts index 93c8f76..25cf218 100644 --- a/src/lib/types.ts +++ b/src/lib/types.ts @@ -44,6 +44,7 @@ export type MiddlewareCall = { export type NestedParams = Omit & { action: NestedAction; scope?: NestedParams; + relation?: Prisma.DMMF.Field; }; export type NestedMiddleware = ( diff --git a/src/lib/utils/actions.ts b/src/lib/utils/actions.ts index 957270a..e43fde1 100644 --- a/src/lib/utils/actions.ts +++ b/src/lib/utils/actions.ts @@ -8,7 +8,7 @@ import { Target, } from "../types"; -import { normaliseRootArgs } from './args'; +import { normaliseRootArgs } from "./args"; export const readActions: NestedReadAction[] = ["include", "select"]; export const writeActions: NestedWriteAction[] = [ @@ -89,6 +89,7 @@ export function extractNestedWriteActions( runInTransaction, dataPath: [], scope: params, + relation, }, })) ); @@ -108,6 +109,7 @@ export function extractNestedWriteActions( runInTransaction, dataPath: [], scope: params, + relation, }, }); }); @@ -138,6 +140,7 @@ export function extractNestedReadActions( runInTransaction, dataPath: [], scope: params, + relation, }, }); @@ -152,6 +155,7 @@ export function extractNestedReadActions( runInTransaction, dataPath: [], scope: params, + relation, }, }); } diff --git a/test/calls.test.ts b/test/calls.test.ts index 35ff522..5b55796 100644 --- a/test/calls.test.ts +++ b/test/calls.test.ts @@ -3,6 +3,7 @@ import faker from "faker"; import { get } from "lodash"; import { createNestedMiddleware, NestedParams } from "../src"; +import { relationsByModel } from "../src/lib/createNestedMiddleware"; import { createParams } from "./utils/createParams"; type MiddlewareCall = { @@ -23,6 +24,7 @@ type MiddlewareCall = { | "select"; argsPath: string; scope?: MiddlewareCall; + relation?: Prisma.DMMF.Field; }; function nestedParamsFromCall( @@ -37,12 +39,22 @@ function nestedParamsFromCall( ); return { ...params, + relation: call.relation, scope: call.scope ? nestedParamsFromCall(rootParams, call.scope) : rootParams, }; } +function getModelRelation( + model: Model, + relationName: string +): Prisma.DMMF.Field | undefined { + return relationsByModel[model].find( + (relation) => relation.name === relationName + ); +} + describe("calls", () => { it("calls middleware once when there are no nested operations", async () => { const middleware = jest.fn((params, next) => next(params)); @@ -77,6 +89,7 @@ describe("calls", () => { action: "create", model: "Profile", argsPath: "args.data.profile.create", + relation: getModelRelation("User", "profile"), }, ], }, @@ -94,6 +107,7 @@ describe("calls", () => { action: "create", model: "Profile", argsPath: "args.data.profile.create", + relation: getModelRelation("User", "profile"), }, ], }, @@ -115,11 +129,13 @@ describe("calls", () => { action: "create", model: "Profile", argsPath: "args.create.profile.create", + relation: getModelRelation("User", "profile"), }, { action: "create", model: "Profile", argsPath: "args.update.profile.create", + relation: getModelRelation("User", "profile"), }, ], }, @@ -147,11 +163,13 @@ describe("calls", () => { action: "create", model: "Post", argsPath: "args.data.posts.create.0", + relation: getModelRelation("User", "posts"), }, { action: "create", model: "Post", argsPath: "args.data.posts.create.1", + relation: getModelRelation("User", "posts"), }, ], }, @@ -180,11 +198,13 @@ describe("calls", () => { action: "create", model: "Post", argsPath: "args.data.posts.create.0", + relation: getModelRelation("User", "posts"), }, { action: "create", model: "Post", argsPath: "args.data.posts.create.1", + relation: getModelRelation("User", "posts"), }, ], }, @@ -212,11 +232,13 @@ describe("calls", () => { action: "update", model: "Profile", argsPath: "args.data.profile.update", + relation: getModelRelation("User", "profile"), }, { action: "create", model: "Post", argsPath: "args.data.posts.create.0", + relation: getModelRelation("User", "posts"), }, ], }, @@ -260,21 +282,25 @@ describe("calls", () => { action: "create", model: "Post", argsPath: "args.create.posts.create.0", + relation: getModelRelation("User", "posts"), }, { action: "create", model: "Post", argsPath: "args.create.posts.create.1", + relation: getModelRelation("User", "posts"), }, { action: "create", model: "Post", argsPath: "args.update.posts.create.0", + relation: getModelRelation("User", "posts"), }, { action: "create", model: "Post", argsPath: "args.update.posts.create.1", + relation: getModelRelation("User", "posts"), }, ], }, @@ -293,6 +319,7 @@ describe("calls", () => { action: "update", model: "Profile", argsPath: "args.data.profile.update", + relation: getModelRelation("User", "profile"), }, ], }, @@ -313,6 +340,7 @@ describe("calls", () => { action: "update", model: "Profile", argsPath: "args.update.profile.update", + relation: getModelRelation("User", "profile"), }, ], }, @@ -347,11 +375,13 @@ describe("calls", () => { action: "update", model: "Post", argsPath: "args.data.posts.update.0", + relation: getModelRelation("User", "posts"), }, { action: "update", model: "Post", argsPath: "args.data.posts.update.1", + relation: getModelRelation("User", "posts"), }, ], }, @@ -389,11 +419,13 @@ describe("calls", () => { action: "update", model: "Post", argsPath: "args.update.posts.update.0", + relation: getModelRelation("User", "posts"), }, { action: "update", model: "Post", argsPath: "args.update.posts.update.1", + relation: getModelRelation("User", "posts"), }, ], }, @@ -416,6 +448,7 @@ describe("calls", () => { action: "upsert", model: "Profile", argsPath: "args.data.profile.upsert", + relation: getModelRelation("User", "profile"), }, ], }, @@ -452,11 +485,13 @@ describe("calls", () => { action: "upsert", model: "Post", argsPath: "args.data.posts.upsert.0", + relation: getModelRelation("User", "posts"), }, { action: "upsert", model: "Post", argsPath: "args.data.posts.upsert.1", + relation: getModelRelation("User", "posts"), }, ], }, @@ -482,6 +517,7 @@ describe("calls", () => { action: "upsert", model: "Profile", argsPath: "args.update.profile.upsert", + relation: getModelRelation("User", "profile"), }, ], }, @@ -499,6 +535,7 @@ describe("calls", () => { action: "delete", model: "Profile", argsPath: "args.data.profile.delete", + relation: getModelRelation("User", "profile"), }, ], }, @@ -519,6 +556,7 @@ describe("calls", () => { action: "delete", model: "Profile", argsPath: "args.update.profile.delete", + relation: getModelRelation("User", "profile"), }, ], }, @@ -541,11 +579,13 @@ describe("calls", () => { action: "delete", model: "Post", argsPath: "args.data.posts.delete.0", + relation: getModelRelation("User", "posts"), }, { action: "delete", model: "Post", argsPath: "args.data.posts.delete.1", + relation: getModelRelation("User", "posts"), }, ], }, @@ -571,11 +611,13 @@ describe("calls", () => { action: "delete", model: "Post", argsPath: "args.update.posts.delete.0", + relation: getModelRelation("User", "posts"), }, { action: "delete", model: "Post", argsPath: "args.update.posts.delete.1", + relation: getModelRelation("User", "posts"), }, ], }, @@ -605,6 +647,7 @@ describe("calls", () => { action: "createMany", model: "Post", argsPath: "args.data.posts.createMany", + relation: getModelRelation("User", "posts"), }, ], }, @@ -635,6 +678,7 @@ describe("calls", () => { action: "createMany", model: "Post", argsPath: "args.data.posts.createMany", + relation: getModelRelation("User", "posts"), }, ], }, @@ -668,6 +712,7 @@ describe("calls", () => { action: "createMany", model: "Post", argsPath: "args.update.posts.createMany", + relation: getModelRelation("User", "posts"), }, ], }, @@ -693,6 +738,7 @@ describe("calls", () => { action: "updateMany", model: "Post", argsPath: "args.data.posts.updateMany", + relation: getModelRelation("User", "posts"), }, ], }, @@ -732,11 +778,13 @@ describe("calls", () => { action: "updateMany", model: "Post", argsPath: "args.data.posts.updateMany.0", + relation: getModelRelation("User", "posts"), }, { action: "updateMany", model: "Post", argsPath: "args.data.posts.updateMany.1", + relation: getModelRelation("User", "posts"), }, ], }, @@ -765,6 +813,7 @@ describe("calls", () => { action: "updateMany", model: "Post", argsPath: "args.update.posts.updateMany", + relation: getModelRelation("User", "posts"), }, ], }, @@ -796,11 +845,13 @@ describe("calls", () => { action: "updateMany", model: "Post", argsPath: "args.update.posts.updateMany.0", + relation: getModelRelation("User", "posts"), }, { action: "updateMany", model: "Post", argsPath: "args.update.posts.updateMany.1", + relation: getModelRelation("User", "posts"), }, ], }, @@ -820,6 +871,7 @@ describe("calls", () => { action: "deleteMany", model: "Post", argsPath: "args.data.posts.deleteMany", + relation: getModelRelation("User", "posts"), }, ], }, @@ -842,11 +894,13 @@ describe("calls", () => { action: "deleteMany", model: "Post", argsPath: "args.data.posts.deleteMany.0", + relation: getModelRelation("User", "posts"), }, { action: "deleteMany", model: "Post", argsPath: "args.data.posts.deleteMany.1", + relation: getModelRelation("User", "posts"), }, ], }, @@ -869,6 +923,7 @@ describe("calls", () => { action: "deleteMany", model: "Post", argsPath: "args.update.posts.deleteMany", + relation: getModelRelation("User", "posts"), }, ], }, @@ -894,11 +949,13 @@ describe("calls", () => { action: "deleteMany", model: "Post", argsPath: "args.update.posts.deleteMany.0", + relation: getModelRelation("User", "posts"), }, { action: "deleteMany", model: "Post", argsPath: "args.update.posts.deleteMany.1", + relation: getModelRelation("User", "posts"), }, ], }, @@ -921,6 +978,7 @@ describe("calls", () => { action: "connectOrCreate", model: "Profile", argsPath: "args.data.profile.connectOrCreate", + relation: getModelRelation("User", "profile"), }, ], }, @@ -946,6 +1004,7 @@ describe("calls", () => { action: "connectOrCreate", model: "Profile", argsPath: "args.update.profile.connectOrCreate", + relation: getModelRelation("User", "profile"), }, ], }, @@ -973,15 +1032,18 @@ describe("calls", () => { action: "create", model: "Post", argsPath: "args.data.posts.create", + relation: getModelRelation("User", "posts"), }, { action: "create", model: "Comment", argsPath: "args.data.posts.create.comments.create", + relation: getModelRelation("Post", "comments"), scope: { action: "create", model: "Post", argsPath: "args.data.posts.create", + relation: getModelRelation("User", "posts"), }, }, ], @@ -1017,15 +1079,18 @@ describe("calls", () => { action: "update", model: "Post", argsPath: "args.data.posts.update", + relation: getModelRelation("User", "posts"), }, { action: "update", model: "Comment", argsPath: "args.data.posts.update.data.comments.update", + relation: getModelRelation("Post", "comments"), scope: { action: "update", model: "Post", argsPath: "args.data.posts.update", + relation: getModelRelation("User", "posts"), }, }, ], @@ -1058,25 +1123,30 @@ describe("calls", () => { action: "update", model: "Post", argsPath: "args.data.posts.update", + relation: getModelRelation("User", "posts"), }, { action: "delete", model: "Comment", argsPath: "args.data.posts.update.data.comments.delete.0", + relation: getModelRelation("Post", "comments"), scope: { action: "update", model: "Post", argsPath: "args.data.posts.update", + relation: getModelRelation("User", "posts"), }, }, { action: "delete", model: "Comment", argsPath: "args.data.posts.update.data.comments.delete.1", + relation: getModelRelation("Post", "comments"), scope: { action: "update", model: "Post", argsPath: "args.data.posts.update", + relation: getModelRelation("User", "posts"), }, }, ], @@ -1119,15 +1189,18 @@ describe("calls", () => { action: "update", model: "Post", argsPath: "args.update.posts.update", + relation: getModelRelation("User", "posts"), }, { action: "upsert", model: "Comment", argsPath: "args.update.posts.update.data.comments.upsert", + relation: getModelRelation("Post", "comments"), scope: { action: "update", model: "Post", argsPath: "args.update.posts.update", + relation: getModelRelation("User", "posts"), }, }, ], @@ -1168,15 +1241,18 @@ describe("calls", () => { action: "update", model: "Post", argsPath: "args.data.posts.update", + relation: getModelRelation("User", "posts"), }, { action: "createMany", model: "Comment", argsPath: "args.data.posts.update.data.comments.createMany", + relation: getModelRelation("Post", "comments"), scope: { action: "update", model: "Post", argsPath: "args.data.posts.update", + relation: getModelRelation("User", "posts"), }, }, ], @@ -1211,15 +1287,18 @@ describe("calls", () => { action: "update", model: "Post", argsPath: "args.data.posts.update", + relation: getModelRelation("User", "posts"), }, { action: "updateMany", model: "Comment", argsPath: "args.data.posts.update.data.comments.updateMany", + relation: getModelRelation("Post", "comments"), scope: { action: "update", model: "Post", argsPath: "args.data.posts.update", + relation: getModelRelation("User", "posts"), }, }, ], @@ -1258,25 +1337,30 @@ describe("calls", () => { action: "update", model: "Post", argsPath: "args.data.posts.update", + relation: getModelRelation("User", "posts"), }, { action: "updateMany", model: "Comment", argsPath: "args.data.posts.update.data.comments.updateMany.0", + relation: getModelRelation("Post", "comments"), scope: { action: "update", model: "Post", argsPath: "args.data.posts.update", + relation: getModelRelation("User", "posts"), }, }, { action: "updateMany", model: "Comment", argsPath: "args.data.posts.update.data.comments.updateMany.1", + relation: getModelRelation("Post", "comments"), scope: { action: "update", model: "Post", argsPath: "args.data.posts.update", + relation: getModelRelation("User", "posts"), }, }, ], @@ -1306,15 +1390,18 @@ describe("calls", () => { action: "update", model: "Post", argsPath: "args.data.posts.update", + relation: getModelRelation("User", "posts"), }, { action: "deleteMany", model: "Comment", argsPath: "args.data.posts.update.data.comments.deleteMany", + relation: getModelRelation("Post", "comments"), scope: { action: "update", model: "Post", argsPath: "args.data.posts.update", + relation: getModelRelation("User", "posts"), }, }, ], @@ -1347,25 +1434,30 @@ describe("calls", () => { action: "update", model: "Post", argsPath: "args.data.posts.update", + relation: getModelRelation("User", "posts"), }, { action: "deleteMany", model: "Comment", argsPath: "args.data.posts.update.data.comments.deleteMany.0", + relation: getModelRelation("Post", "comments"), scope: { action: "update", model: "Post", argsPath: "args.data.posts.update", + relation: getModelRelation("User", "posts"), }, }, { action: "deleteMany", model: "Comment", argsPath: "args.data.posts.update.data.comments.deleteMany.1", + relation: getModelRelation("Post", "comments"), scope: { action: "update", model: "Post", argsPath: "args.data.posts.update", + relation: getModelRelation("User", "posts"), }, }, ], @@ -1401,15 +1493,18 @@ describe("calls", () => { action: "update", model: "Post", argsPath: "args.data.posts.update", + relation: getModelRelation("User", "posts"), }, { action: "connectOrCreate", model: "Comment", argsPath: "args.data.posts.update.data.comments.connectOrCreate", + relation: getModelRelation("Post", "comments"), scope: { action: "update", model: "Post", argsPath: "args.data.posts.update", + relation: getModelRelation("User", "posts"), }, }, ], @@ -1427,6 +1522,7 @@ describe("calls", () => { action: "include", model: "Post", argsPath: "args.include.posts", + relation: getModelRelation("User", "posts"), }, ], }, @@ -1441,6 +1537,7 @@ describe("calls", () => { action: "include", model: "Post", argsPath: "args.include.posts", + relation: getModelRelation("User", "posts"), }, ], }, @@ -1455,6 +1552,7 @@ describe("calls", () => { action: "include", model: "Post", argsPath: "args.include.posts", + relation: getModelRelation("User", "posts"), }, ], }, @@ -1472,11 +1570,13 @@ describe("calls", () => { action: "create", model: "Post", argsPath: "args.data.posts.create", + relation: getModelRelation("User", "posts"), }, { action: "include", model: "Post", argsPath: "args.include.posts", + relation: getModelRelation("User", "posts"), }, ], }, @@ -1494,6 +1594,7 @@ describe("calls", () => { action: "include", model: "Post", argsPath: "args.include.posts", + relation: getModelRelation("User", "posts"), }, ], }, @@ -1514,6 +1615,7 @@ describe("calls", () => { action: "include", model: "Post", argsPath: "args.include.posts", + relation: getModelRelation("User", "posts"), }, ], }, @@ -1534,15 +1636,18 @@ describe("calls", () => { action: "include", model: "Post", argsPath: "args.include.posts", + relation: getModelRelation("User", "posts"), }, { action: "include", model: "Comment", argsPath: "args.include.posts.include.comments", + relation: getModelRelation("Post", "comments"), scope: { action: "include", model: "Post", argsPath: "args.include.posts", + relation: getModelRelation("User", "posts"), }, }, ], @@ -1568,29 +1673,35 @@ describe("calls", () => { action: "include", model: "Post", argsPath: "args.include.posts", + relation: getModelRelation("User", "posts"), }, { action: "include", model: "Comment", argsPath: "args.include.posts.include.comments", + relation: getModelRelation("Post", "comments"), scope: { action: "include", model: "Post", argsPath: "args.include.posts", + relation: getModelRelation("User", "posts"), }, }, { action: "include", model: "Comment", argsPath: "args.include.posts.include.comments.include.replies", + relation: getModelRelation("Comment", "replies"), scope: { action: "include", model: "Comment", argsPath: "args.include.posts.include.comments", + relation: getModelRelation("Post", "comments"), scope: { action: "include", model: "Post", argsPath: "args.include.posts", + relation: getModelRelation("User", "posts"), }, }, }, @@ -1609,6 +1720,7 @@ describe("calls", () => { action: "select", model: "Post", argsPath: "args.select.posts", + relation: getModelRelation("User", "posts"), }, ], }, @@ -1623,6 +1735,7 @@ describe("calls", () => { action: "select", model: "Post", argsPath: "args.select.posts", + relation: getModelRelation("User", "posts"), }, ], }, @@ -1637,6 +1750,7 @@ describe("calls", () => { action: "select", model: "Post", argsPath: "args.select.posts", + relation: getModelRelation("User", "posts"), }, ], }, @@ -1654,11 +1768,13 @@ describe("calls", () => { action: "create", model: "Post", argsPath: "args.data.posts.create", + relation: getModelRelation("User", "posts"), }, { action: "select", model: "Post", argsPath: "args.select.posts", + relation: getModelRelation("User", "posts"), }, ], }, @@ -1676,6 +1792,7 @@ describe("calls", () => { action: "select", model: "Post", argsPath: "args.select.posts", + relation: getModelRelation("User", "posts"), }, ], }, @@ -1696,6 +1813,7 @@ describe("calls", () => { action: "select", model: "Post", argsPath: "args.select.posts", + relation: getModelRelation("User", "posts"), }, ], }, @@ -1716,15 +1834,18 @@ describe("calls", () => { action: "select", model: "Post", argsPath: "args.select.posts", + relation: getModelRelation("User", "posts"), }, { action: "select", model: "Comment", argsPath: "args.select.posts.select.comments", + relation: getModelRelation("Post", "comments"), scope: { action: "select", model: "Post", argsPath: "args.select.posts", + relation: getModelRelation("User", "posts"), }, }, ], @@ -1750,31 +1871,35 @@ describe("calls", () => { action: "select", model: "Post", argsPath: "args.select.posts", + relation: getModelRelation("User", "posts"), }, { action: "select", model: "Comment", argsPath: "args.select.posts.select.comments", + relation: getModelRelation("Post", "comments"), scope: { action: "select", model: "Post", argsPath: "args.select.posts", + relation: getModelRelation("User", "posts"), }, }, { action: "select", model: "Comment", argsPath: "args.select.posts.select.comments.select.replies", - + relation: getModelRelation("Comment", "replies"), scope: { action: "select", model: "Comment", argsPath: "args.select.posts.select.comments", - + relation: getModelRelation("Post", "comments"), scope: { action: "select", model: "Post", argsPath: "args.select.posts", + relation: getModelRelation("User", "posts"), }, }, }, @@ -1808,29 +1933,35 @@ describe("calls", () => { action: "select", model: "Post", argsPath: "args.select.posts", + relation: getModelRelation("User", "posts"), }, { action: "select", model: "Comment", argsPath: "args.select.posts.select.comments", + relation: getModelRelation("Post", "comments"), scope: { action: "select", model: "Post", argsPath: "args.select.posts", + relation: getModelRelation("User", "posts"), }, }, { action: "select", model: "Comment", argsPath: "args.select.posts.select.comments.select.replies", + relation: getModelRelation("Comment", "replies"), scope: { action: "select", model: "Comment", argsPath: "args.select.posts.select.comments", + relation: getModelRelation("Post", "comments"), scope: { action: "select", model: "Post", argsPath: "args.select.posts", + relation: getModelRelation("User", "posts"), }, }, }, @@ -1853,20 +1984,24 @@ describe("calls", () => { action: "include", model: "Post", argsPath: "args.include.posts", + relation: getModelRelation("User", "posts"), }, { action: "select", model: "Post", argsPath: "args.include.posts.select", + relation: getModelRelation("User", "posts"), }, { action: "select", model: "Comment", argsPath: "args.include.posts.select.comments", + relation: getModelRelation("Post", "comments"), scope: { action: "include", model: "Post", argsPath: "args.include.posts", + relation: getModelRelation("User", "posts"), }, }, ], @@ -1888,15 +2023,18 @@ describe("calls", () => { action: "select", model: "Post", argsPath: "args.select.posts", + relation: getModelRelation("User", "posts"), }, { action: "include", model: "Comment", argsPath: "args.select.posts.include.comments", + relation: getModelRelation("Post", "comments"), scope: { action: "select", model: "Post", argsPath: "args.select.posts", + relation: getModelRelation("User", "posts"), }, }, ], @@ -1922,25 +2060,30 @@ describe("calls", () => { action: "include", model: "Post", argsPath: "args.include.posts", + relation: getModelRelation("User", "posts"), }, { action: "include", model: "Comment", argsPath: "args.include.posts.include.comments", + relation: getModelRelation("Post", "comments"), scope: { action: "include", model: "Post", argsPath: "args.include.posts", + relation: getModelRelation("User", "posts"), }, }, { action: "select", model: "Comment", argsPath: "args.include.posts.include.comments.select", + relation: getModelRelation("Post", "comments"), scope: { action: "include", model: "Post", argsPath: "args.include.posts", + relation: getModelRelation("User", "posts"), }, }, ], @@ -1966,29 +2109,35 @@ describe("calls", () => { action: "select", model: "Post", argsPath: "args.select.posts", + relation: getModelRelation("User", "posts"), }, { action: "select", model: "Comment", argsPath: "args.select.posts.select.comments", + relation: getModelRelation("Post", "comments"), scope: { action: "select", model: "Post", argsPath: "args.select.posts", + relation: getModelRelation("User", "posts"), }, }, { action: "include", model: "User", argsPath: "args.select.posts.select.comments.include.author", + relation: getModelRelation("Comment", "author"), scope: { action: "select", model: "Comment", argsPath: "args.select.posts.select.comments", + relation: getModelRelation("Post", "comments"), scope: { action: "select", model: "Post", argsPath: "args.select.posts", + relation: getModelRelation("User", "posts"), }, }, }, @@ -2024,30 +2173,36 @@ describe("calls", () => { action: "create", model: "Post", argsPath: "args.data.posts.create", + relation: getModelRelation("User", "posts"), }, { action: "create", model: "Comment", argsPath: "args.data.posts.create.comments.create", + relation: getModelRelation("Post", "comments"), scope: { action: "create", model: "Post", argsPath: "args.data.posts.create", + relation: getModelRelation("User", "posts"), }, }, { action: "include", model: "Post", argsPath: "args.include.posts", + relation: getModelRelation("User", "posts"), }, { action: "include", model: "Comment", argsPath: "args.include.posts.include.comments", + relation: getModelRelation("Post", "comments"), scope: { action: "include", model: "Post", argsPath: "args.include.posts", + relation: getModelRelation("User", "posts"), }, }, ], @@ -2082,30 +2237,36 @@ describe("calls", () => { action: "create", model: "Post", argsPath: "args.data.posts.create", + relation: getModelRelation("User", "posts"), }, { action: "create", model: "Comment", argsPath: "args.data.posts.create.comments.create", + relation: getModelRelation("Post", "comments"), scope: { action: "create", model: "Post", argsPath: "args.data.posts.create", + relation: getModelRelation("User", "posts"), }, }, { action: "select", model: "Post", argsPath: "args.select.posts", + relation: getModelRelation("User", "posts"), }, { action: "select", model: "Comment", argsPath: "args.select.posts.select.comments", + relation: getModelRelation("Post", "comments"), scope: { action: "select", model: "Post", argsPath: "args.select.posts", + relation: getModelRelation("User", "posts"), }, }, ],