Skip to content

Commit

Permalink
fix(queries): query generation for camelCased fields on related data (#…
Browse files Browse the repository at this point in the history
  • Loading branch information
romain-gilliotte authored Aug 9, 2021
1 parent b0f337a commit a6fa9d5
Showing 1 changed file with 10 additions and 5 deletions.
15 changes: 10 additions & 5 deletions src/utils/sequelize-compatibility.js
Original file line number Diff line number Diff line change
Expand Up @@ -20,11 +20,16 @@ function bubbleWheresInPlace(operators, options) {
bubbleWheresInPlace(operators, include);

if (include.where) {
const newWhere = ObjectTools.mapKeysDeep(include.where, (key) => (
key[0] === '$' && key[key.length - 1] === '$'
? `$${include.as}.${key.substring(1)}`
: `$${include.as}.${key}$`
));
const newWhere = ObjectTools.mapKeysDeep(include.where, (key) => {
// Targeting a nested field, simply nest it deeper.
if (key[0] === '$' && key[key.length - 1] === '$') {
return `$${include.as}.${key.substring(1)}`;
}

// Targeting a simple field.
// Try to resolve the column name, as sequelize does not allow using model aliases here.
return `$${include.as}.${include.model?.rawAttributes?.[key]?.field ?? key}$`;
});

options.where = QueryUtils.mergeWhere(operators, options.where, newWhere);
delete include.where;
Expand Down

0 comments on commit a6fa9d5

Please sign in to comment.