* 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)
| 3639 | * @returns {object|any} |
| 3640 | */ |
| 3641 | get(key, options) { |
| 3642 | if (options === undefined && typeof key === 'object') { |
| 3643 | options = key; |
| 3644 | key = undefined; |
| 3645 | } |
| 3646 | |
| 3647 | options = options || {}; |
| 3648 | |
| 3649 | if (key) { |
| 3650 | if (Object.prototype.hasOwnProperty.call(this._customGetters, key) && !options.raw) { |
| 3651 | return this._customGetters[key].call(this, key, options); |
| 3652 | } |
| 3653 | |
| 3654 | if (options.plain && this._options.include && this._options.includeNames.includes(key)) { |
| 3655 | if (Array.isArray(this.dataValues[key])) { |
| 3656 | return this.dataValues[key].map(instance => instance.get(options)); |
| 3657 | } |
| 3658 | if (this.dataValues[key] instanceof Model) { |
| 3659 | return this.dataValues[key].get(options); |
| 3660 | } |
| 3661 | return this.dataValues[key]; |
| 3662 | } |
| 3663 | |
| 3664 | return this.dataValues[key]; |
| 3665 | } |
| 3666 | |
| 3667 | if ( |
| 3668 | this._hasCustomGetters |
| 3669 | || options.plain && this._options.include |
| 3670 | || options.clone |
| 3671 | ) { |
| 3672 | const values = {}; |
| 3673 | let _key; |
| 3674 | |
| 3675 | if (this._hasCustomGetters) { |
| 3676 | for (_key in this._customGetters) { |
| 3677 | if ( |
| 3678 | this._options.attributes |
| 3679 | && !this._options.attributes.includes(_key) |
| 3680 | ) { |
| 3681 | continue; |
| 3682 | } |
| 3683 | |
| 3684 | if (Object.prototype.hasOwnProperty.call(this._customGetters, _key)) { |
| 3685 | values[_key] = this.get(_key, options); |
| 3686 | } |
| 3687 | } |
| 3688 | } |
| 3689 | |
| 3690 | for (_key in this.dataValues) { |
| 3691 | if ( |
| 3692 | !Object.prototype.hasOwnProperty.call(values, _key) |
| 3693 | && Object.prototype.hasOwnProperty.call(this.dataValues, _key) |
| 3694 | ) { |
| 3695 | values[_key] = this.get(_key, options); |
| 3696 | } |
| 3697 | } |
| 3698 |
no test coverage detected