MCPcopy
hub / github.com/sequelize/sequelize / _addDefaultAttributes

Method _addDefaultAttributes

src/model.js:243–313  ·  view source on GitHub ↗
()

Source from the content-addressed store, hash-verified

241 }
242
243 static _addDefaultAttributes() {
244 const tail = {};
245 let head = {};
246
247 // Add id if no primary key was manually added to definition
248 // Can't use this.primaryKeys here, since this function is called before PKs are identified
249 if (!_.some(this.rawAttributes, 'primaryKey')) {
250 if ('id' in this.rawAttributes) {
251 // Something is fishy here!
252 throw new Error(`A column called 'id' was added to the attributes of '${this.tableName}' but not marked with 'primaryKey: true'`);
253 }
254
255 head = {
256 id: {
257 type: new DataTypes.INTEGER(),
258 allowNull: false,
259 primaryKey: true,
260 autoIncrement: true,
261 _autoGenerated: true
262 }
263 };
264 }
265
266 if (this._timestampAttributes.createdAt) {
267 tail[this._timestampAttributes.createdAt] = {
268 type: DataTypes.DATE,
269 allowNull: false,
270 _autoGenerated: true
271 };
272 }
273
274 if (this._timestampAttributes.updatedAt) {
275 tail[this._timestampAttributes.updatedAt] = {
276 type: DataTypes.DATE,
277 allowNull: false,
278 _autoGenerated: true
279 };
280 }
281
282 if (this._timestampAttributes.deletedAt) {
283 tail[this._timestampAttributes.deletedAt] = {
284 type: DataTypes.DATE,
285 _autoGenerated: true
286 };
287 }
288
289 if (this._versionAttribute) {
290 tail[this._versionAttribute] = {
291 type: DataTypes.INTEGER,
292 allowNull: false,
293 defaultValue: 0,
294 _autoGenerated: true
295 };
296 }
297
298 const newRawAttributes = {
299 ...head,
300 ...this.rawAttributes

Callers 1

initMethod · 0.95

Calls

no outgoing calls

Tested by

no test coverage detected