-
Notifications
You must be signed in to change notification settings - Fork 74
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
Patching with query does not return expected results in query property was patched #346
Comments
I started implementing this in a PR and ran into a few unexpected snags. The tests are failing for the common adapter tests. Which I can't seem to find. The code references My basic implementation was this const findQuery = { [this.id]: { $in: idList } };
if (params.query && params.query.$select) {
findQuery.$select = [...params.query.$select];
}
if (params.query && params.query.$sort) {
findQuery.$sort = Object.assign({}, params.query.$sort);
}
const findParams = Object.assign({}, params, { query: findQuery }); This solution skips merging the rest of the As clean as I think it is to just keep that minimal query, I am sure there are cases it will fail to cover. Another solution may be to modify the // This is the code that is currently implemented for findParams
const findParams = Object.assign({}, params, Object.assign({}, {
query: Object.assign({ [this.id]: { $in: idList } }, params.query)
}));
// Loop over the data and update the findParams.query to what we expect the record
// to have been updated to, rather than trying to query by what the record was before update
Object.keys(data).forEach(key => {
if (params && params.query[key]) {
findParams.query[key] = data[key];
}
}); |
Ha, good timing I actually just moved those to /~https://github.com/feathersjs/databases ... yesterday 😺 What would be great to start with would be a PR to with a failing test for the cases. I think you are totally right and feathers-sequelize/lib/index.js Line 238 in 8b46599
query: { [this.id]: { $in: idList } } Potentially merged with the query filtered params ( |
Closed via #350 |
When patching with a query where the updated data also contains the property of the query, the method does not return any results.
For example
This line is where the problem is:
feathers-sequelize/lib/index.js
Line 238 in 8b46599
The query that is built to re-query the results is creating an impossible state in this instance
I am not quite sure the best way to handle this. We could make the new query be just the
{ id: { $in: idList }
. That is accurate and would work. We don't really need the rest of theparams.query
becauseparams.query
has already produced theidList
for us. But we lose access the the$select
and potentially some other things?We could also add the
idList
in an$or
. Maybe something likeProbably the best solution is to keep just the
idList
and$select
. TheidList
is the only "query" that we need. Although$select
is in the query, its intent is not to "query" data but rather to "filter" it. And$select
is the only operator in which this is the case (at least in the common feathers query standard). So I think it is safe to just keep it.The text was updated successfully, but these errors were encountered: