(attributes, Model)
| 185 | exports.mapOptionFieldNames = mapOptionFieldNames; |
| 186 | |
| 187 | function mapWhereFieldNames(attributes, Model) { |
| 188 | if (attributes) { |
| 189 | attributes = cloneDeep(attributes); |
| 190 | getComplexKeys(attributes).forEach(attribute => { |
| 191 | const rawAttribute = Model.rawAttributes[attribute]; |
| 192 | |
| 193 | if (rawAttribute && rawAttribute.field !== rawAttribute.fieldName) { |
| 194 | attributes[rawAttribute.field] = attributes[attribute]; |
| 195 | delete attributes[attribute]; |
| 196 | } |
| 197 | |
| 198 | if (_.isPlainObject(attributes[attribute]) |
| 199 | && !(rawAttribute && ( |
| 200 | rawAttribute.type instanceof DataTypes.HSTORE |
| 201 | || rawAttribute.type instanceof DataTypes.JSON))) { // Prevent renaming of HSTORE & JSON fields |
| 202 | attributes[attribute] = mapOptionFieldNames({ |
| 203 | where: attributes[attribute] |
| 204 | }, Model).where; |
| 205 | } |
| 206 | |
| 207 | if (Array.isArray(attributes[attribute])) { |
| 208 | attributes[attribute].forEach((where, index) => { |
| 209 | if (_.isPlainObject(where)) { |
| 210 | attributes[attribute][index] = mapWhereFieldNames(where, Model); |
| 211 | } |
| 212 | }); |
| 213 | } |
| 214 | |
| 215 | }); |
| 216 | } |
| 217 | |
| 218 | return attributes; |
| 219 | } |
| 220 | exports.mapWhereFieldNames = mapWhereFieldNames; |
| 221 | |
| 222 | /* Used to map field names in values */ |
no test coverage detected