* A Model represents a table in the database. Instances of this class represent a database row. * * Model instances operate with the concept of a `dataValues` property, which stores the actual values represented by the instance. * By default, the values from dataValues can also be accessed direct
| 51 | * @mixes Hooks |
| 52 | */ |
| 53 | class Model { |
| 54 | static get queryInterface() { |
| 55 | return this.sequelize.getQueryInterface(); |
| 56 | } |
| 57 | |
| 58 | static get queryGenerator() { |
| 59 | return this.queryInterface.queryGenerator; |
| 60 | } |
| 61 | |
| 62 | /** |
| 63 | * A reference to the sequelize instance |
| 64 | * |
| 65 | * @see |
| 66 | * {@link Sequelize} |
| 67 | * |
| 68 | * @property sequelize |
| 69 | * |
| 70 | * @returns {Sequelize} |
| 71 | */ |
| 72 | get sequelize() { |
| 73 | return this.constructor.sequelize; |
| 74 | } |
| 75 | |
| 76 | /** |
| 77 | * Builds a new model instance. |
| 78 | * |
| 79 | * @param {object} [values={}] an object of key value pairs |
| 80 | * @param {object} [options] instance construction options |
| 81 | * @param {boolean} [options.raw=false] If set to true, values will ignore field and virtual setters. |
| 82 | * @param {boolean} [options.isNewRecord=true] Is this a new record |
| 83 | * @param {Array} [options.include] an array of include options - Used to build prefetched/included model instances. See `set` |
| 84 | */ |
| 85 | constructor(values = {}, options = {}) { |
| 86 | if (!this.constructor._overwrittenAttributesChecked) { |
| 87 | this.constructor._overwrittenAttributesChecked = true; |
| 88 | |
| 89 | // setTimeout is hacky but necessary. |
| 90 | // Public Class Fields declared by descendants of this class |
| 91 | // will not be available until after their call to super, so after |
| 92 | // this constructor is done running. |
| 93 | setTimeout(() => { |
| 94 | const overwrittenAttributes = []; |
| 95 | for (const key of Object.keys(this.constructor._attributeManipulation)) { |
| 96 | if (Object.prototype.hasOwnProperty.call(this, key)) { |
| 97 | overwrittenAttributes.push(key); |
| 98 | } |
| 99 | } |
| 100 | |
| 101 | if (overwrittenAttributes.length > 0) { |
| 102 | logger.warn(`Model ${JSON.stringify(this.constructor.name)} is declaring public class fields for attribute(s): ${overwrittenAttributes.map(attr => JSON.stringify(attr)).join(', ')}.` + |
| 103 | '\nThese class fields are shadowing Sequelize\'s attribute getters & setters.' + |
| 104 | '\nSee https://sequelize.org/main/manual/model-basics.html#caveat-with-public-class-fields'); |
| 105 | } |
| 106 | }, 0); |
| 107 | } |
| 108 | |
| 109 | options = { |
| 110 | isNewRecord: true, |
nothing calls this directly
no outgoing calls
no test coverage detected