Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 8970151
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 15, 20262026-06-15T17:41:30+00:00 2026-06-15T17:41:30+00:00

I have a model defined as follows : var userTableConfig = { username: {

  • 0

I have a model defined as follows :

 
var userTableConfig = {
    username: {
      type: Sequelize.STRING,
      allowNull: false,
      unique: true,
      validate: {
        len: [5, 30],
        is: ['[a-z0-9_]', 'i']
      }
    },
    email: {
      type: Sequelize.STRING,
      allowNull: false,
      unique: true,
      validate: {
        isEmail: true,
        len: [5, 30]
      }
    },
    ............. // Other fields
}

var userConfig =  userConfig = {
    underscored: true,
    instanceMethods: {
        ..............
    }
}

var User = seq.define('User', userTableConfig, userConfig);

Now when I use this model as follows :


    u = User.build();
    u.username = this.param('username');    // Contains empty string
    u.setPassword(this.param('password'));  // Contains empty string
    u.email = this.param('email');
    u.activation_state = 'pending';

    if (u.validate()) {
      console.log("Validation succeeded");
    } else {
      console.log("Validation failed");
      console.log(u.errors);
      .............
    }

Despite the length constraints not being met, the validator gladly succeeds and I see Validation succeeded in my console.

Taking it a step further, I could also push in arbitrary random characters which should not be validated by the regular expression constaints and the validator gladly accepts them as well.

So, I decided to check if the validators were at being run, and tried to check that using a custom validator:


  userTableConfig = {
    username: {
      type: Sequelize.STRING,
      allowNull: false,
      unique: true,
      validate: {
        randomValidator: function() {
          console.log("===========> validator executed");
          throw new Error('Hell with validation');
          return false;
        },
        len: [5, 30],
        is: ['[a-z0-9_]', 'i']
      }
    },
    ......
  }

What is ironical is that, the method randomValidator does get executed, and yet the validate method succeeds without throwing any error or returning false.

What is it that I am doing wrong and how should the above issue be rectified?

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-06-15T17:41:30+00:00Added an answer on June 15, 2026 at 5:41 pm

    I figured out what the problem was :

    The validate method does not return a boolean value indicating whether or not validation succeeded. Rather it returns an array of hashes matching fields to an array of errors thrown.

    So instead of checking the truth value as :

    
    if (u.validate()) {
          console.log("Validation succeeded");
        } else {
          console.log("Validation failed");
          console.log(u.errors);
          .............
        }
    

    I should have checked the length of the array returned by u.validate().

    Apart from this, what is quite counter-intuitive with Sequelize (esp. if you are coming from Rails) is that save does not perform implicit validation.

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I have a model defined as below: class Example(models.Model): user = models.ForeignKey(User, null=True) other
Suppose I have a field f in my model defined as follows as a
I have the following issue with Django: My model is defined as follows: from
I have a model field defined as follows: class Room(models.Model): ... ... is_course =
I have a model with some relations defined as follows. public function relations() {
I have a :belongs_to association defined on model Brand as follows: belongs_to :loyalty_coupon, :class_name
I have a model defined as follows: class User extends ActiveRecord\Model { function get_name()
I have a core data model defined as follows: A User has many events.
I have a model defined as follows: public class Link extends Model { @Required
suppose we have a model in django defined as follows: class Literal: name =

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.