Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Fix aliased DB table names in filter query #13575

Merged
merged 3 commits into from Jun 14, 2022

Conversation

licitdev
Copy link
Member

@licitdev licitdev commented May 26, 2022

Filters involving relational fields may result in aliased table names in subqueries.
Parsing of variables are not processed as the alias (below).
This PR is crucial as it fixes the filtering of relational fields with date types in SQLite.

if (collection in schema.collections && field in schema.collections[collection].fields) {
const type = schema.collections[collection].fields[field].type;
if (['date', 'dateTime', 'time', 'timestamp'].includes(type)) {
if (Array.isArray(compareValue)) {
compareValue = compareValue.map((val) => helpers.date.parse(val));
} else {
compareValue = helpers.date.parse(compareValue);
}
}
if (['bigInteger', 'integer', 'float', 'decimal'].includes(type)) {
if (Array.isArray(compareValue)) {
compareValue = compareValue.map((val) => Number(val));
} else {
compareValue = Number(compareValue);
}
}
}

@licitdev licitdev marked this pull request as ready for review May 26, 2022 14:22
api/src/utils/apply-query.ts Outdated Show resolved Hide resolved
@rijkvanzanten rijkvanzanten merged commit f8b73ce into directus:main Jun 14, 2022
@rijkvanzanten rijkvanzanten added this to the v9-next milestone Jun 14, 2022
@licitdev licitdev deleted the fix/aliased-filter-query branch June 14, 2022 13:32
@licitdev licitdev mentioned this pull request Jul 14, 2022
9 tasks
@github-actions github-actions bot locked as resolved and limited conversation to collaborators Feb 2, 2024
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
Projects
None yet
Development

Successfully merging this pull request may close these issues.

None yet

3 participants