* Search for a single instance by its primary key._ * * @param {number|string|Buffer} param The value of the desired instance's primary key. * @param {object} [options] find options * @param {Transaction} [options.transaction] Transaction to run q
(param, options)
| 1875 | * @returns {Promise<Model>} |
| 1876 | */ |
| 1877 | static async findByPk(param, options) { |
| 1878 | class="cm">// return Promise resolved with null if no arguments are passed |
| 1879 | if ([null, undefined].includes(param)) { |
| 1880 | return null; |
| 1881 | } |
| 1882 | |
| 1883 | options = Utils.cloneDeep(options) || {}; |
| 1884 | |
| 1885 | if (typeof param === class="st">'number' || typeof param === class="st">'string' || Buffer.isBuffer(param)) { |
| 1886 | options.where = { |
| 1887 | [this.primaryKeyAttribute]: param |
| 1888 | }; |
| 1889 | } else { |
| 1890 | throw new Error(`Argument passed to findByPk is invalid: ${param}`); |
| 1891 | } |
| 1892 | |
| 1893 | class="cm">// Bypass a possible overloaded findOne |
| 1894 | return await this.findOne(options); |
| 1895 | } |
| 1896 | |
| 1897 | /** |
| 1898 | * Search for a single instance. Returns the first instance found, or null if none can be found. |