* Search for multiple instances. * * @example Simple search using AND and = * Model.findAll({ * where: { * attr1: 42, * attr2: 'cake' * } * }) * * # WHERE attr1 = 42 AND attr2 = 'cake' * * @example Using greater than, less t
(options)
| 1742 | * @returns {Promise<Array<Model>>} |
| 1743 | */ |
| 1744 | static async findAll(options) { |
| 1745 | if (options !== undefined && !_.isPlainObject(options)) { |
| 1746 | throw new sequelizeErrors.QueryError('The argument passed to findAll must be an options object, use findByPk if you wish to pass a single primary key value'); |
| 1747 | } |
| 1748 | |
| 1749 | if (options !== undefined && options.attributes) { |
| 1750 | if (!Array.isArray(options.attributes) && !_.isPlainObject(options.attributes)) { |
| 1751 | throw new sequelizeErrors.QueryError('The attributes option must be an array of column names or an object'); |
| 1752 | } |
| 1753 | } |
| 1754 | |
| 1755 | this.warnOnInvalidOptions(options, Object.keys(this.rawAttributes)); |
| 1756 | |
| 1757 | const tableNames = {}; |
| 1758 | |
| 1759 | tableNames[this.getTableName(options)] = true; |
| 1760 | options = Utils.cloneDeep(options); |
| 1761 | |
| 1762 | // Add CLS transaction |
| 1763 | if (options.transaction === undefined && this.sequelize.constructor._cls) { |
| 1764 | const t = this.sequelize.constructor._cls.get('transaction'); |
| 1765 | if (t) { |
| 1766 | options.transaction = t; |
| 1767 | } |
| 1768 | } |
| 1769 | |
| 1770 | _.defaults(options, { hooks: true }); |
| 1771 | |
| 1772 | // set rejectOnEmpty option, defaults to model options |
| 1773 | options.rejectOnEmpty = Object.prototype.hasOwnProperty.call(options, 'rejectOnEmpty') |
| 1774 | ? options.rejectOnEmpty |
| 1775 | : this.options.rejectOnEmpty; |
| 1776 | |
| 1777 | this._injectScope(options); |
| 1778 | |
| 1779 | if (options.hooks) { |
| 1780 | await this.runHooks('beforeFind', options); |
| 1781 | } |
| 1782 | this._conformIncludes(options, this); |
| 1783 | this._expandAttributes(options); |
| 1784 | this._expandIncludeAll(options); |
| 1785 | |
| 1786 | if (options.hooks) { |
| 1787 | await this.runHooks('beforeFindAfterExpandIncludeAll', options); |
| 1788 | } |
| 1789 | options.originalAttributes = this._injectDependentVirtualAttributes(options.attributes); |
| 1790 | |
| 1791 | if (options.include) { |
| 1792 | options.hasJoin = true; |
| 1793 | |
| 1794 | this._validateIncludedElements(options, tableNames); |
| 1795 | |
| 1796 | // If we're not raw, we have to make sure we include the primary key for de-duplication |
| 1797 | if ( |
| 1798 | options.attributes |
| 1799 | && !options.raw |
| 1800 | && this.primaryKeyAttribute |
| 1801 | && !options.attributes.includes(this.primaryKeyAttribute) |