josx / ra-data-feathers

A feathers rest client for react-admin
MIT License
157 stars 53 forks source link

Filtering by nested properties #52

Closed dprentis closed 6 years ago

dprentis commented 6 years ago

Can't filter by nested properties, because query object is not flattened in restClient.js.

eg. when trying to filter author.lastName='Brown', the query object becomes { author: { lastName: 'Brown' } }, which results in an invalid query string. I think it should be { 'author.lastName': 'Brown' }.

Easy fix seems to be to import fetchUtils import { fetchUtils } from 'admin-on-rest'; and then replace Object.assign(query, params.filter); here https://github.com/josx/aor-feathers-client/blob/master/src/restClient.js#L50 with Object.assign(query, fetchUtils.flattenObject(params.filter));

josx commented 6 years ago

hey! good catch! Please make a PR for that feature and also for a test.

dprentis commented 6 years ago

PR here: https://github.com/josx/aor-feathers-client/pull/53

I needed to upgrade admin-on-rest, so updated to latest version. Seems version 1.0.1 used before, didn't handle flattening filters either.

dprentis commented 6 years ago

Thanks for merging it! :) When are you planning the next release?

josx commented 6 years ago

I think will be in the following days ;)

josx commented 6 years ago

done!