Skip to content

Commit

Permalink
Adding documentation for second parameter for set function
Browse files Browse the repository at this point in the history
  • Loading branch information
fishcharlie committed May 9, 2020
1 parent 5c5a750 commit 7a6aa7d
Showing 1 changed file with 11 additions and 0 deletions.
11 changes: 11 additions & 0 deletions docs/docs/guide/Schema.md
Expand Up @@ -326,6 +326,17 @@ You can use a set function on an attribute to be run whenever saving a document
}
```

Unlike `get` this method will additionally pass in the original value as the second parameter (if avaiable). Internally Dynamoose uses the [`document.original()`](Document#documentoriginal) method to access the original value. This means that using [`Model.batchPut`](Model#modelbatchputdocuments-settings-callback), [`Model.update`](Model#modelupdatekey-updateobj-settings-callback) or any other document save method that does not have access to [`document.original()`](Document#documentoriginal) this second parameter will be `undefined`.

```js
{
"name": {
"type": String,
"set": (newValue, oldValue) => `${newValue.charAt(0).toUpperCase()}${newValue.slice(1)}-${oldValue.charAt(0).toUpperCase()}${oldValue.slice(1)}` // Prepend the newValue to the oldValue (split by a `-`) and capitalize first letter of each when saving to database
}
}
```

### index: boolean | object | array

You can define indexes on properties to be created or updated upon model initialization. If you pass in an array for the value of this setting it must be an array of index objects. By default no indexes are specified on the attribute.
Expand Down

1 comment on commit 7a6aa7d

@vercel
Copy link

@vercel vercel bot commented on 7a6aa7d May 9, 2020

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Deployment failed with the following error:

The most recent charge for your active payment method has failed. Please update it here: https://zeit.co/teams/dynamoose/settings/billing

Please sign in to comment.