diff --git a/src/services/BaseEntityService.ts b/src/services/BaseEntityService.ts index 392c81e..e26a49e 100644 --- a/src/services/BaseEntityService.ts +++ b/src/services/BaseEntityService.ts @@ -411,6 +411,18 @@ export default abstract class BaseEntityService extends TaskManager { query(m: IModel, queryFunction?: keyof TR, ... args: any[]): Query { + let entityKey; + if (args.length) { + const first = args[0]; + if (first) { + const { $key, $type } = first; + if ($key && $type) { + // this is an entity, and must be sent as an entity key + entityKey = $key; + args.splice(0, 1); + } + } + } return new Query({ service: this, name: m.name, diff --git a/src/services/Query.ts b/src/services/Query.ts index 78355ea..3e986c4 100644 --- a/src/services/Query.ts +++ b/src/services/Query.ts @@ -128,6 +128,7 @@ interface IQueryContext { traceQuery?: boolean; queryFunction?: string; args?: any[]; + entityKey?: string; queryProcessor?: "DotNet" | "JavaScript" } @@ -324,6 +325,7 @@ export default class Query { name, service, queryFunction, + entityKey, args } = this.context; @@ -347,6 +349,9 @@ export default class Query { if (queryFunction) { fm.append("function", queryFunction); fm.append("args", JSON.stringify(args ?? "[]")); + if (entityKey) { + fm.append("entityKey", entityKey); + } } if (expandable) { fm.append("expandable", "1"); @@ -369,7 +374,8 @@ export default class Query { trace, expandable: expandable ? 1 : void 0, function: queryFunction || void 0, - args: queryFunction ? args : void 0 + args: queryFunction ? args : void 0, + entityKey: entityKey ?? void 0 }) .asJson(); // @ts-expect-error