Unique email validation before create new record
See original GitHub issueAm trying to validate Email already exists validation in Bookshelf.js when creating new record.
I found one solution here github but its not working, even i tried with Promise
User = bookshelf.Model.extend({
tableName: 'users',
initialize: function() {
this.on('saving', this._assertEmailUnique);
},
_assertEmailUnique: function(model, attributes, options) {
if (this.hasChanged('email')) {
return this
.query('where', 'email', this.get('email'))
.fetch(_.pick(options, 'transacting'))
.then(function (existing) {
if (!existing) throw new Error('duplicate email');
});
}
}
});
For Model validation currently am using Joi, looks like Joi also not supporting for custom validation for this. Am using Postgres Database. There is any other way to do it… Please help…
Issue Analytics
- State:
- Created 7 years ago
- Reactions:1
- Comments:8 (3 by maintainers)
Top Results From Across the Web
Bookshelf.js unique email validation before create new record
Am trying to validate Email already exists validation in Bookshelf.js when creating new record. I found one solution here github but its not ......
Read more >Unique email validation - ServiceNow Community
I have a Record Producer to create a record on the sys_user table. I have an OnSubmit client script that checks the email...
Read more >Unique Record Validation | Tadabase
In this short article we'll look into 3 different unique record validation approaches available to you. Assigning unique record validation on the field...
Read more >Validation - IHP Guide
Validating An Email Is Unique You can use |> validateIsUnique #email to validate that an email is unique for a given record. This...
Read more >Validations & Constraints - Sequelize
The most basic example of constraint is an Unique Constraint. ... Validations are automatically run on create , update and save .
Read more >
Top Related Medium Post
No results found
Top Related StackOverflow Question
No results found
Troubleshoot Live Code
Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free
Top Related Reddit Thread
No results found
Top Related Hackernoon Post
No results found
Top Related Tweet
No results found
Top Related Dev.to Post
No results found
Top Related Hashnode Post
No results found
Just put a unique constraint on the column…
On Wed, Jul 6, 2016, 8:51 PM raj-optisol notifications@github.com wrote:
Here’s what I’m using. Start with a unique constraint.
Then count duplicates on each create or save, respecting transactions, and filtering out the current model from the count.
Then run the assertion for any model with unique constraints.
It should work for most use cases.