MCPcopy
hub / github.com/sequelize/sequelize / get

Method get

lib/model.js:3515–3577  ·  lib/model.js::Model.get

* If no key is given, returns all values of the instance, also invoking virtual getters. * * If key is given and a field or virtual getter is present for the key it will call that getter - else it will return the value for key. * * @param {string} [key] key to get value of * @param {

(key, options)

Source from the content-addressed store, hash-verified

3513 * @returns {object|any}
3514 */
3515 get(key, options) {
3516 if (options === undefined && typeof key === class="st">'object') {
3517 options = key;
3518 key = undefined;
3519 }
3520
3521 options = options || {};
3522
3523 if (key) {
3524 if (Object.prototype.hasOwnProperty.call(this._customGetters, key) && !options.raw) {
3525 return this._customGetters[key].call(this, key, options);
3526 }
3527
3528 if (options.plain && this._options.include && this._options.includeNames.includes(key)) {
3529 if (Array.isArray(this.dataValues[key])) {
3530 return this.dataValues[key].map(instance => instance.get(options));
3531 }
3532 if (this.dataValues[key] instanceof Model) {
3533 return this.dataValues[key].get(options);
3534 }
3535 return this.dataValues[key];
3536 }
3537
3538 return this.dataValues[key];
3539 }
3540
3541 if (
3542 this._hasCustomGetters
3543 || options.plain && this._options.include
3544 || options.clone
3545 ) {
3546 const values = {};
3547 let _key;
3548
3549 if (this._hasCustomGetters) {
3550 for (_key in this._customGetters) {
3551 if (
3552 this._options.attributes
3553 && !this._options.attributes.includes(_key)
3554 ) {
3555 continue;
3556 }
3557
3558 if (Object.prototype.hasOwnProperty.call(this._customGetters, _key)) {
3559 values[_key] = this.get(_key, options);
3560 }
3561 }
3562 }
3563
3564 for (_key in this.dataValues) {
3565 if (
3566 !Object.prototype.hasOwnProperty.call(values, _key)
3567 && Object.prototype.hasOwnProperty.call(this.dataValues, _key)
3568 ) {
3569 values[_key] = this.get(_key, options);
3570 }
3571 }
3572

Callers 6

refreshAttributesMethod · 0.95
whereMethod · 0.95
saveMethod · 0.95
isSoftDeletedMethod · 0.95
equalsMethod · 0.95
toJSONMethod · 0.95

Calls 1

getMethod · 0.65

Tested by

no test coverage detected