Skip to content

Commit

Permalink
feat: Force _rev for queries with .select fields
Browse files Browse the repository at this point in the history
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.
  • Loading branch information
Ldoppea committed Sep 5, 2024
1 parent 9c55ca9 commit 78848de
Show file tree
Hide file tree
Showing 2 changed files with 4 additions and 4 deletions.
6 changes: 3 additions & 3 deletions packages/cozy-pouch-link/src/CozyPouchLink.js
Original file line number Diff line number Diff line change
Expand Up @@ -564,9 +564,9 @@ class PouchLink extends CozyLink {
const findOpts = {
sort,
selector: findSelector,
// same selector as Document Collection. We force _id.
// Fix https://github.com/cozy/cozy-client/issues/985
fields: fields ? [...fields, '_id', '_type', 'class'] : undefined,
// same selector as Document Collection.
// _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
fields: fields ? [...fields, '_id', '_rev'] : undefined,
limit,
skip
}
Expand Down
2 changes: 1 addition & 1 deletion packages/cozy-pouch-link/src/CozyPouchLink.spec.js
Original file line number Diff line number Diff line change
Expand Up @@ -313,7 +313,7 @@ describe('CozyPouchLink', () => {
expect(find).toHaveBeenLastCalledWith(
expect.anything(),
expect.objectContaining({
fields: ['label', 'done', '_id', '_type', 'class']
fields: ['label', 'done', '_id', '_rev']
})
)
})
Expand Down

0 comments on commit 78848de

Please sign in to comment.