Skip to content

Instantly share code, notes, and snippets.

@calmdev
Last active December 17, 2015 23:09
Show Gist options
  • Save calmdev/5687025 to your computer and use it in GitHub Desktop.
Save calmdev/5687025 to your computer and use it in GitHub Desktop.

Revisions

  1. calmdev revised this gist May 31, 2013. 1 changed file with 2 additions and 2 deletions.
    4 changes: 2 additions & 2 deletions validation.js
    Original file line number Diff line number Diff line change
    @@ -7,7 +7,7 @@ user.validate().success(function() {
    });
    });

    // Still trying to get this validation method working on my model:
    // Still trying to get this isUnique validation method working on my model:
    email: {
    type: DataTypes.STRING,
    validate: {
    @@ -26,7 +26,7 @@ email: {

    // When the isUnique is added to my model, calling .validate(); generates:
    Error: Email is already registered.
    at null.<anonymous> (/Web/api.grooptrip.com/models/User.js:82:13)
    at null.<anonymous> (/Web/models/User.js:82:13)
    at EventEmitter.emit (events.js:95:17)
    at null.<anonymous> (/Code/sequelize/lib/query-interface.js:392:17)
    at EventEmitter.emit (events.js:117:20)
  2. calmdev revised this gist May 31, 2013. 1 changed file with 32 additions and 1 deletion.
    33 changes: 32 additions & 1 deletion validation.js
    Original file line number Diff line number Diff line change
    @@ -1,7 +1,38 @@
    // This validation check works:
    user.validate().success(function() {
    user.save().success(function(user){
    console.log(user);
    }).error(function(errors) {
    console.log(errors);
    });
    });
    });

    // Still trying to get this validation method working on my model:
    email: {
    type: DataTypes.STRING,
    validate: {
    isEmail: {
    msg: 'Invalid email address.'
    },
    isUnique: function(value) {
    app.get('MODELS').User.find({
    where: { email: value }
    }).success(function(account) {
    throw new Error('Email is already registered.'); // Alone, this line works fine.
    });
    }
    }
    }

    // When the isUnique is added to my model, calling .validate(); generates:
    Error: Email is already registered.
    at null.<anonymous> (/Web/api.grooptrip.com/models/User.js:82:13)
    at EventEmitter.emit (events.js:95:17)
    at null.<anonymous> (/Code/sequelize/lib/query-interface.js:392:17)
    at EventEmitter.emit (events.js:117:20)
    at null.<anonymous> (/Code/sequelize/lib/dialects/mysql/query.js:32:14)
    at Query.Sequence.end (/Code/sequelize/node_modules/mysql/lib/protocol/sequences/Sequence.js:66:24)
    at Query._handleFinalResultPacket (/Code/sequelize/node_modules/mysql/lib/protocol/sequences/Query.js:143:8)
    at Query.EofPacket (/Code/sequelize/node_modules/mysql/lib/protocol/sequences/Query.js:127:8)
    at Protocol._parsePacket (/Code/sequelize/node_modules/mysql/lib/protocol/Protocol.js:172:24)
    at Parser.write (/Code/sequelize/node_modules/mysql/lib/protocol/Parser.js:62:12)
  3. calmdev created this gist May 31, 2013.
    7 changes: 7 additions & 0 deletions validation.js
    Original file line number Diff line number Diff line change
    @@ -0,0 +1,7 @@
    user.validate().success(function() {
    user.save().success(function(user){
    console.log(user);
    }).error(function(errors) {
    console.log(errors);
    });
    });