Skip to content

Fix Collection.update() may erase values #86

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Closed
wants to merge 1 commit into from

Conversation

fzaninotto
Copy link
Member

Problem

Calling Collection.update() with an object containing undefined values erases the existing value.

// will erase the title
collection.updateOne(0, { name: 'FOO', title: undefined });

This does not mimic true REST APIs because, when the change payload is serialized to be passed to the network, undefined values are removed.

The erasure is unexpected.

Solution

Better mimic REST APIs by serializing / unserializing the changes before applying them.

## Problem

Calling `Collection.update()` with an object containing `undefined` values erases the existing value.

```jsx
// will erase the title
collection.updateOne(0, { name: 'FOO', title: undefined });
```

This does not mimic true REST APIs because, when the change payload is serialized to be passed to the network, undefined values are removed.

The erasure is unexpected.

## Solution

Better mimic REST APIs by serializing / unserializing the changes before applying them.
@fzaninotto fzaninotto added the RFR Ready For Review label Sep 30, 2024
@fzaninotto
Copy link
Member Author

This has to be done at the fake server level, not at the collection or database level. FetchMock, MSW and Sinon adapters work properly, the problem only occurs in ra-data-fakerest. That's where the fix should be done.

@fzaninotto fzaninotto closed this Sep 30, 2024
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
RFR Ready For Review
Projects
None yet
Development

Successfully merging this pull request may close these issues.

1 participant