diff --git a/packages/query/src/index.ts b/packages/query/src/index.ts index 964f67251d..14ab8d8f67 100644 --- a/packages/query/src/index.ts +++ b/packages/query/src/index.ts @@ -47,6 +47,7 @@ import core, { WithTx, WorkspaceEvent, checkMixinKey, + clone, findProperty, generateId, getObjectValue, @@ -352,12 +353,13 @@ export class LiveQuery implements WithTx, Client { callback: { callback: (result: FindResult) => void, callbackId: string } | undefined, options?: FindOptions ): Query { + const _query: DocumentQuery = clone(query) const localResult = this.refs.findFromDocs(_class, query, options) const result = localResult != null ? Promise.resolve(localResult) : this.client.findAll(_class, query, options) const q: Query = { id: ++this.queryCounter, _class, - query, + query: _query, result: result.then((docs) => new ResultArray(docs, this.getHierarchy())), total: 0, options: options as FindOptions, diff --git a/server/postgres/src/storage.ts b/server/postgres/src/storage.ts index 88b8610a5a..8f4c5fdfc0 100644 --- a/server/postgres/src/storage.ts +++ b/server/postgres/src/storage.ts @@ -803,11 +803,12 @@ abstract class PostgresAdapterBase implements DbAdapter { private buildQuery( _class: Ref>, baseDomain: string, - query: DocumentQuery, + _query: DocumentQuery, joins: JoinProps[], options?: ServerFindOptions ): string { const res: string[] = [] + const query = { ..._query } res.push(`${baseDomain}."workspaceId" = '${this.workspaceId.name}'`) if (options?.skipClass !== true) { query._class = this.fillClass(_class, query) as any