Updating
Last updated
Last updated
Use and to change resource data. The following operations are possible:
Using update()
:
merge new data with an existing resource
replace a resource with new data
update a single attribute of a resource
Using remove()
:
remove attributes and meta from an existing resource
Updating a resource is identical to the call to create one.
In this example, we are updating the name and publish year of the resource with an ID of 24:
By default, the resource data that you pass will be deeply merged with any existing resource.
If you would like to outright replace an existing resource, you can pass a third argument to update
: an Object with mergeResources: false
.
If this resource had any other attributes or meta before this call to update()
, they would be removed.
By using the first argument to update
, you can scope your update to a single attribute, or even a deeply nested piece of a single attribute.
In the following example, we are updating the English display name for the book with an ID of 24.
You can update as many resources as you want with a single call to update
, even across different resource types. In the following example, we update two books and an author with one call.
You can remove a specific attribute using store.remove()
. In the following example, we remove the releaseYear
attribute from the book with ID of 24.