balderdashy/waterline — pull request #681 by connor4312 (2014-10-08 03:15:22+00:00)
Title: Guard

Guarding ability as seen in #649, just had to move it to a new branch.

Previously, there wasn't a really _good_ way of updating a model's attributes en masse (e.g. from form input) without manually filtering out attributes you didn't want to have the user be able to set. That doesn't lend itself to very DRY design, and is a pain in the neck!

I've added the ability to denote "guarded" properties of the model, then use a method "fill" to effectively extend the model based on dirty input.

For example, you can have a model like:
```js
{
attributes: {
id: {
type: 'integer',
autoIncrement: true,
primaryKey: true,
unique: true
},
email: { type: 'email' }
},
guarded: ['id']
}
```

Now, by calling `model.fill(input)`, the user would only be able to change their email, _not_ their ID. Additionally, anything given in the "input" which is not an attribute of the model will be discarded.