Skip to content

DataStore update with predicate code snippet is incorrect #5231

@david-mcafee

Description

@david-mcafee

Describe the content issue:
A clear and concise description of what the content issue is. Is there content missing or is there incorrect content?

The following code snippet is incorrect:

await DataStore.save(
  new Post({
    title: 'My First Post',
    rating: 10,
    status: PostStatus.INACTIVE
  }),
  (p) => p.title.beginsWith('[Amplify]')
);

The predicate here does nothing, and each save that utilizes a predicate will create a new record (not conditionally update an existing record, as would be expected). The code snippet should instead be as follows:

await DataStore.save(
  Post.copyOf(original, updated => {
      updated.title = 'My First Post';
    }),
    p => p.title.beginsWith('[Amplify]')
);

URL page where content issue is:
https://docs.amplify.aws/lib/datastore/sync/q/platform/js/#update-and-delete-with-predicate

Metadata

Metadata

Labels

amplify/dataIssue related to aws-amplify/amplify-category-api

Type

No type

Projects

No projects

Milestone

No milestone

Relationships

None yet

Development

No branches or pull requests

Issue actions