(attributes, Model)
| 198 | exports.mapOptionFieldNames = mapOptionFieldNames; |
| 199 | |
| 200 | function mapWhereFieldNames(attributes, Model) { |
| 201 | if (attributes) { |
| 202 | attributes = cloneDeep(attributes); |
| 203 | getComplexKeys(attributes).forEach(attribute => { |
| 204 | const rawAttribute = Model.rawAttributes[attribute]; |
| 205 | |
| 206 | if (rawAttribute && rawAttribute.field !== rawAttribute.fieldName) { |
| 207 | attributes[rawAttribute.field] = attributes[attribute]; |
| 208 | delete attributes[attribute]; |
| 209 | } |
| 210 | |
| 211 | if (_.isPlainObject(attributes[attribute]) |
| 212 | && !(rawAttribute && ( |
| 213 | rawAttribute.type instanceof DataTypes.HSTORE |
| 214 | || rawAttribute.type instanceof DataTypes.JSON))) { // Prevent renaming of HSTORE & JSON fields |
| 215 | attributes[attribute] = mapOptionFieldNames({ |
| 216 | where: attributes[attribute] |
| 217 | }, Model).where; |
| 218 | } |
| 219 | |
| 220 | if (Array.isArray(attributes[attribute])) { |
| 221 | attributes[attribute].forEach((where, index) => { |
| 222 | if (_.isPlainObject(where)) { |
| 223 | attributes[attribute][index] = mapWhereFieldNames(where, Model); |
| 224 | } |
| 225 | }); |
| 226 | } |
| 227 | |
| 228 | }); |
| 229 | } |
| 230 | |
| 231 | return attributes; |
| 232 | } |
| 233 | exports.mapWhereFieldNames = mapWhereFieldNames; |
| 234 | |
| 235 | /* Used to map field names in values */ |
no test coverage detected