* Will validate a single field against its schema definition (isnull). * * @param {object} rawAttribute As defined in the Schema. * @param {string} field The field name. * @param {*} value anything. * * @private
(rawAttribute, field, value)
| 344 | * @private |
| 345 | */ |
| 346 | _validateSchema(rawAttribute, field, value) { |
| 347 | if (rawAttribute.allowNull === false && (value === null || value === undefined)) { |
| 348 | const association = Object.values(this.modelInstance.constructor.associations).find(association => association instanceof BelongsTo && association.foreignKey === rawAttribute.fieldName); |
| 349 | if (!association || !this.modelInstance.get(association.associationAccessor)) { |
| 350 | const validators = this.modelInstance.validators[field]; |
| 351 | const errMsg = _.get(validators, 'notNull.msg', `${this.modelInstance.constructor.name}.${field} cannot be null`); |
| 352 | |
| 353 | this.errors.push(new sequelizeError.ValidationErrorItem( |
| 354 | errMsg, |
| 355 | 'notNull Violation', // sequelizeError.ValidationErrorItem.Origins.CORE, |
| 356 | field, |
| 357 | value, |
| 358 | this.modelInstance, |
| 359 | 'is_null' |
| 360 | )); |
| 361 | } |
| 362 | } |
| 363 | |
| 364 | if (rawAttribute.type instanceof DataTypes.STRING || rawAttribute.type instanceof DataTypes.TEXT || rawAttribute.type instanceof DataTypes.CITEXT) { |
| 365 | if (Array.isArray(value) || _.isObject(value) && !(value instanceof Utils.SequelizeMethod) && !Buffer.isBuffer(value)) { |
| 366 | this.errors.push(new sequelizeError.ValidationErrorItem( |
| 367 | `${field} cannot be an array or an object`, |
| 368 | 'string violation', // sequelizeError.ValidationErrorItem.Origins.CORE, |
| 369 | field, |
| 370 | value, |
| 371 | this.modelInstance, |
| 372 | 'not_a_string' |
| 373 | )); |
| 374 | } |
| 375 | } |
| 376 | } |
| 377 | |
| 378 | /** |
| 379 | * Signs all errors retaining the original. |
no test coverage detected