-
Notifications
You must be signed in to change notification settings - Fork 376
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Overriding model getters/setters? #66
Comments
It's strange the uniqe validator is not working, since it just searches the model for that property. You can have your own unique validator, maybe you can spot the bug :p Maybe the |
Try now: User = db.define('user',{
email: String
},{
validations: {
email: orm.validators.unique()
},
hooks: {
beforeSave: function() {
this.email = this.email.toLowerCase();
}
}
}); |
Thanks, that fixes it. |
Hey, say I have a model like:
All is jolly, however:
We now have two duplicate users.
(I actually have a unique index on the table to prevent this, but it throws an ugly error when saving)
I can think of two ways of solving this:
beforeValidate
hook.I imagine it working something like this:
Or maybe even more fancy:
where it defaults to the standard getter as one isn't specified, and
setAttribute
calls the default setter.What do you think?
The text was updated successfully, but these errors were encountered: