Reputation: 502
For example: we have the model Profile. Each user profile has attribute alias_name
that can be set only once (when you create), and can not be changed (when you update).
Of course I can override action .update()
in the controller and remove the attribute from req.body
. But then lost all the magic Blueprint API.
More I can create special policies that will remove the attribute from req.body
. But not sure it's right.
Perhaps it should be made in the method .beforeUpdate()
in the Profile model?
How better to do? Share your experiences?
Upvotes: 1
Views: 223
Reputation: 13164
You can use approach with custom validation rule for this attribute
// /api/models/profile.js
module.exports = {
attributes: {
alias_name: {
type: 'string',
nonEditable: true
}
},
// ...
types: {
nonEditable: function(prop) {
return prop === null;
}
}
}
Thus, this fields can be changed only once (in case you have not defaultsTo
specified for alias_name
).
Upvotes: 1