(options, model, subQuery)
| 2063 | } |
| 2064 | |
| 2065 | getQueryOrders(options, model, subQuery) { |
| 2066 | const mainQueryOrder = []; |
| 2067 | const subQueryOrder = []; |
| 2068 | |
| 2069 | if (Array.isArray(options.order)) { |
| 2070 | for (let order of options.order) { |
| 2071 | |
| 2072 | class="cm">// wrap if not array |
| 2073 | if (!Array.isArray(order)) { |
| 2074 | order = [order]; |
| 2075 | } |
| 2076 | |
| 2077 | if ( |
| 2078 | subQuery |
| 2079 | && Array.isArray(order) |
| 2080 | && order[0] |
| 2081 | && !(order[0] instanceof Association) |
| 2082 | && !(typeof order[0] === class="st">'function' && order[0].prototype instanceof Model) |
| 2083 | && !(typeof order[0].model === class="st">'function' && order[0].model.prototype instanceof Model) |
| 2084 | && !(typeof order[0] === class="st">'string' && model && model.associations !== undefined && model.associations[order[0]]) |
| 2085 | ) { |
| 2086 | subQueryOrder.push(this.quote(order, model, class="st">'->')); |
| 2087 | } |
| 2088 | |
| 2089 | if (subQuery) { |
| 2090 | class="cm">// Handle case where sub-query renames attribute we want to order by, |
| 2091 | class="cm">// see https://github.com/sequelize/sequelize/issues/8739 |
| 2092 | const subQueryAttribute = options.attributes.find(a => Array.isArray(a) && a[0] === order[0] && a[1]); |
| 2093 | if (subQueryAttribute) { |
| 2094 | const modelName = this.quoteIdentifier(model.name); |
| 2095 | |
| 2096 | order[0] = new Utils.Col(this._getAliasForField(modelName, subQueryAttribute[1], options) || subQueryAttribute[1]); |
| 2097 | } |
| 2098 | } |
| 2099 | |
| 2100 | mainQueryOrder.push(this.quote(order, model, class="st">'->')); |
| 2101 | } |
| 2102 | } else if (options.order instanceof Utils.SequelizeMethod) { |
| 2103 | const sql = this.quote(options.order, model, class="st">'->'); |
| 2104 | if (subQuery) { |
| 2105 | subQueryOrder.push(sql); |
| 2106 | } |
| 2107 | mainQueryOrder.push(sql); |
| 2108 | } else { |
| 2109 | throw new Error(class="st">'Order must be type of array or instance of a valid sequelize method.'); |
| 2110 | } |
| 2111 | |
| 2112 | return { mainQueryOrder, subQueryOrder }; |
| 2113 | } |
| 2114 | |
| 2115 | _throwOnEmptyAttributes(attributes, extraInfo = {}) { |
| 2116 | if (attributes.length > 0) return; |
no test coverage detected