MCPcopy
hub / github.com/sequelize/sequelize / mapWhereFieldNames

Function mapWhereFieldNames

lib/utils.js:187–219  ·  view source on GitHub ↗
(attributes, Model)

Source from the content-addressed store, hash-verified

185exports.mapOptionFieldNames = mapOptionFieldNames;
186
187function 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}
220exports.mapWhereFieldNames = mapWhereFieldNames;
221
222/* Used to map field names in values */

Callers 1

mapOptionFieldNamesFunction · 0.85

Calls 3

cloneDeepFunction · 0.85
getComplexKeysFunction · 0.85
mapOptionFieldNamesFunction · 0.85

Tested by

no test coverage detected