Skip to content

Commit 3f3c38b

Browse files
committed
feat: Force _rev for queries with .select fields
This commit is a copy of #1517 applied to CozyPouchLink When specifying fields in a query, e.g. `Q('io.cozy.todos').where({done: true}).select(['date'])`, the revision was missing if not explicitly given. This is now problematic because we rely on the revision existence to identify "virtual" documents, i.e. not persisted in CouchDB, that never have any revision. See #1486 for more insights.
1 parent b461876 commit 3f3c38b

2 files changed

Lines changed: 4 additions & 4 deletions

File tree

packages/cozy-pouch-link/src/CozyPouchLink.js

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -564,9 +564,9 @@ class PouchLink extends CozyLink {
564564
const findOpts = {
565565
sort,
566566
selector: findSelector,
567-
// same selector as Document Collection. We force _id.
568-
// Fix https://github.com/cozy/cozy-client/issues/985
569-
fields: fields ? [...fields, '_id', '_type', 'class'] : undefined,
567+
// same selector as Document Collection.
568+
// _id is necessary for the store, and _rev is required for offline. See https://github.com/cozy/cozy-client/blob/95978d39546023920b0c01d689fed5dd41577a02/packages/cozy-client/src/CozyClient.js#L1153
569+
fields: fields ? [...fields, '_id', '_rev'] : undefined,
570570
limit,
571571
skip
572572
}

packages/cozy-pouch-link/src/CozyPouchLink.spec.js

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -313,7 +313,7 @@ describe('CozyPouchLink', () => {
313313
expect(find).toHaveBeenLastCalledWith(
314314
expect.anything(),
315315
expect.objectContaining({
316-
fields: ['label', 'done', '_id', '_type', 'class']
316+
fields: ['label', 'done', '_id', '_rev']
317317
})
318318
)
319319
})

0 commit comments

Comments
 (0)