MCPcopy
hub / github.com/sequelize/sequelize / normalizeAttribute

Method normalizeAttribute

lib/sequelize.js:1235–1266  ·  view source on GitHub ↗
(attribute)

Source from the content-addressed store, hash-verified

1233 }
1234
1235 normalizeAttribute(attribute) {
1236 if (!_.isPlainObject(attribute)) {
1237 attribute = { type: attribute };
1238 }
1239
1240 if (!attribute.type) return attribute;
1241
1242 attribute.type = this.normalizeDataType(attribute.type);
1243
1244 if (Object.prototype.hasOwnProperty.call(attribute, 'defaultValue')) {
1245 if (typeof attribute.defaultValue === 'function' &&
1246 [DataTypes.NOW, DataTypes.UUIDV1, DataTypes.UUIDV4].includes(attribute.defaultValue)
1247 ) {
1248 attribute.defaultValue = new attribute.defaultValue();
1249 }
1250 }
1251
1252 if (attribute.type instanceof DataTypes.ENUM) {
1253 // The ENUM is a special case where the type is an object containing the values
1254 if (attribute.values) {
1255 attribute.type.values = attribute.type.options.values = attribute.values;
1256 } else {
1257 attribute.values = attribute.type.values;
1258 }
1259
1260 if (!attribute.values.length) {
1261 throw new Error('Values for ENUM have not been defined.');
1262 }
1263 }
1264
1265 return attribute;
1266 }
1267}
1268
1269// Aliases

Callers 2

initMethod · 0.45
add-column.test.jsFile · 0.45

Calls 1

normalizeDataTypeMethod · 0.95

Tested by

no test coverage detected