Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
6 changes: 3 additions & 3 deletions types/lib/model.d.ts
Original file line number Diff line number Diff line change
Expand Up @@ -1109,13 +1109,13 @@ export interface ModelValidateOptions {
/**
* check the value is not one of these
*/
notIn?: ReadonlyArray<readonly string[]> | { msg: string; args: ReadonlyArray<readonly string[]> };
notIn?: ReadonlyArray<readonly any[]> | { msg: string; args: ReadonlyArray<readonly any[]> };

/**
* check the value is one of these
*/
isIn?: ReadonlyArray<readonly string[]> | { msg: string; args: ReadonlyArray<readonly string[]> };

isIn?: ReadonlyArray<readonly any[]> | { msg: string; args: ReadonlyArray<readonly any[]> };
/**
* don't allow specific substrings
*/
Expand Down
22 changes: 22 additions & 0 deletions types/test/validators.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,22 @@
import { DataTypes, Model, Sequelize } from 'sequelize';

const sequelize = new Sequelize('mysql://user:user@localhost:3306/mydb');

/**
* Test for isIn/notIn validation - should accept any[]
*/
class ValidatedUser extends Model {}
ValidatedUser.init({
name: {
type: DataTypes.STRING,
validate: {
isIn: [['first', 1, null]]
}
},
email: {
type: DataTypes.STRING,
validate: {
notIn: [['second', 2, null]]
Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I would have somehow expected that we would have e.g. an INTEGER column and hence verify that the value is no part of a list of numbers or so.

Also, is that syntax correct? Why array of array and not ['first', 1, null]

Copy link
Copy Markdown
Contributor Author

@lukashroch lukashroch Oct 16, 2021

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

test was written to demonstrate that type works, i.e. it accepts other types not just string. Real world would be different, as you say e.g. list of int and int data type.

Syntax is how sequelize implements it (https://github.com/sequelize/sequelize/blob/main/types/lib/model.d.ts#L1112 or https://sequelize.org/master/manual/validations-and-constraints.html), I haven't really change that. Just a type since validator.js allows any for this validation.

}
},
}, { sequelize });