MCPcopy
hub / github.com/sequelize/sequelize / _validateSchema

Method _validateSchema

lib/instance-validator.js:346–376  ·  view source on GitHub ↗

* 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)

Source from the content-addressed store, hash-verified

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.

Callers 1

Calls 1

getMethod · 0.65

Tested by

no test coverage detected