MCPcopy
hub / github.com/sequelize/sequelize / Model

Class Model

lib/model.js:53–4536  ·  view source on GitHub ↗

* 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

Source from the content-addressed store, hash-verified

51 * @mixes Hooks
52 */
53class 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 options = {
87 isNewRecord: true,
88 _schema: this.constructor._schema,
89 _schemaDelimiter: this.constructor._schemaDelimiter,
90 ...options
91 };
92
93 if (options.attributes) {
94 options.attributes = options.attributes.map(attribute => Array.isArray(attribute) ? attribute[1] : attribute);
95 }
96
97 if (!options.includeValidated) {
98 this.constructor._conformIncludes(options, this.constructor);
99 if (options.include) {
100 this.constructor._expandIncludeAll(options);
101 this.constructor._validateIncludedElements(options);
102 }
103 }
104
105 this.dataValues = {};
106 this._previousDataValues = {};
107 this.uniqno = 1;
108 this._changed = new Set();
109 this._options = options;
110

Callers

nothing calls this directly

Calls

no outgoing calls

Tested by

no test coverage detected