Skip to content
Open
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
Original file line number Diff line number Diff line change
Expand Up @@ -194,11 +194,12 @@ You also can conditionally allow `null` values, with a custom validator, since i
class User extends Model {}
User.init(
{
age: Sequelize.INTEGER,
age: DataTypes.INTEGER,
name: {
type: DataTypes.STRING,
allowNull: true,
validate: {
/** @this {User} */
customValidator(value) {
if (value === null && this.age !== 10) {
throw new Error("name can't be null unless age is 10");
Expand Down Expand Up @@ -245,8 +246,8 @@ An example:
class Place extends Model {}
Place.init(
{
name: Sequelize.STRING,
address: Sequelize.STRING,
name: DataTypes.STRING,
address: DataTypes.STRING,
latitude: {
type: DataTypes.INTEGER,
validate: {
Expand All @@ -265,6 +266,7 @@ Place.init(
{
sequelize,
validate: {
/** @this {Place} */
bothCoordsOrNone() {
if ((this.latitude === null) !== (this.longitude === null)) {
throw new Error('Either both latitude and longitude, or neither!');
Expand Down
Loading