-
Notifications
You must be signed in to change notification settings - Fork 362
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
hasMany through - filter/where/order not working #166
Comments
When using hasAndBelongsToMany of hasManyThrought and making a find on relation (with api or with model) filter apply to the throught model and not on the destination model. This is a huge problem. |
+1 |
+1 indeed! (to @lchenay 's comment) - and I'm interested in both hasAndBelongsToMany and hasManyThrought, just fyi Thanks! |
+1 also did just run into the same issue with hasAndBelongsToMany. Wanted to use "fields". |
FYI, for now I'm JSON stringifying and then JSON parsing the results of my queries... very inneficient but works:
|
Possible solution at #476 |
@raymondfeng Is this related to strongloop/loopback/issues/1076? |
@superkhau I think so. Can you verify? |
@fabien What is |
Hi @raymondfeng, the fix is published in 3.x and I am not sure should I backport it to 2.x? |
@jannyHou What are the breaking changes? How much effort is needed to backport to 2.x? |
I believe this may be still broken in 3.x . I have a TopUser extended from User which hasMany Role, but the response of |
@kristojorg could you fork https://github.com/strongloop/loopback-sandbox and provide me your code? Thanks. |
+1 |
Wow this is a big problem. {where} filter does not map to target model. I'd like to fix it in a fork. Have looked at the libraries - wouldn't it make sense to have Also please confirm - is the problem persisting in |
The fix is already released in 2.55.0 and also released long time ago in [email protected], otherwise tests won't pass: Could anyone provide me a sandbox that reproduce the problem? see #166 (comment) |
@jannyHou I tried. Couldn't reproduce. I'm using Mongo ObjectId's in every id field including reference id fields in relational tables. I think it's somehow related to this. If I catch anything related with mongo connector, shall I continue reporting here ? |
Thank you @ilkerc, if it's a mongodb specific problem, then https://github.com/strongloop/loopback-connector-mongodb would be the best place to open issue and discuss. |
@jannyHou as far as I can see, those tests you mentioned only test the case when filter is an id. If I change the where condition to be, for example, name or any other attribute, then the query stops working. |
@mbenedettini Thank you I think it's caused by same reason as issue strongloop/loopback#3487 reported. I am going to close this issue since the original bug is fixed in [email protected], the failures you observe is caused by another bug. |
Let's keep discussion in issue strongloop/loopback#3487, which should reflect the filter issue you run into recently. |
Example:
/api/spaces/client-a/users?filter[where][username]=toby
// result: []Example:
/api/spaces/client-a/users?filter[order]=username
// result: unordered arrayRegarding sorting, since models are fetched individually (byId vs. find), ordering is not applied either. This might very well be a limitation of how juggler handles relations at the moment (very flexible regarding mixed datasources, but not optimal performance wise).
I think the best approach would be to gather the related ids from the through-model first, then issue a second query on the actual target model, scoped to the previously retrieved ids - this is not only more efficient, but should enable the filtering capabilities as expected.
The text was updated successfully, but these errors were encountered: