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

Method _addDefaultAttributes

lib/model.js:220–290  ·  view source on GitHub ↗
()

Source from the content-addressed store, hash-verified

218 }
219
220 static _addDefaultAttributes() {
221 const tail = {};
222 let head = {};
223
224 // Add id if no primary key was manually added to definition
225 // Can't use this.primaryKeys here, since this function is called before PKs are identified
226 if (!_.some(this.rawAttributes, 'primaryKey')) {
227 if ('id' in this.rawAttributes) {
228 // Something is fishy here!
229 throw new Error(`A column called 'id' was added to the attributes of '${this.tableName}' but not marked with 'primaryKey: true'`);
230 }
231
232 head = {
233 id: {
234 type: new DataTypes.INTEGER(),
235 allowNull: false,
236 primaryKey: true,
237 autoIncrement: true,
238 _autoGenerated: true
239 }
240 };
241 }
242
243 if (this._timestampAttributes.createdAt) {
244 tail[this._timestampAttributes.createdAt] = {
245 type: DataTypes.DATE,
246 allowNull: false,
247 _autoGenerated: true
248 };
249 }
250
251 if (this._timestampAttributes.updatedAt) {
252 tail[this._timestampAttributes.updatedAt] = {
253 type: DataTypes.DATE,
254 allowNull: false,
255 _autoGenerated: true
256 };
257 }
258
259 if (this._timestampAttributes.deletedAt) {
260 tail[this._timestampAttributes.deletedAt] = {
261 type: DataTypes.DATE,
262 _autoGenerated: true
263 };
264 }
265
266 if (this._versionAttribute) {
267 tail[this._versionAttribute] = {
268 type: DataTypes.INTEGER,
269 allowNull: false,
270 defaultValue: 0,
271 _autoGenerated: true
272 };
273 }
274
275 const newRawAttributes = {
276 ...head,
277 ...this.rawAttributes

Callers 1

initMethod · 0.95

Calls

no outgoing calls

Tested by

no test coverage detected