-
Notifications
You must be signed in to change notification settings - Fork 20
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
Sorting on deeply nested resources #43
Conversation
src/index.js
Outdated
@@ -554,7 +554,10 @@ export default (Bookshelf, options = {}) => { | |||
|
|||
_forEach(sortValues, (sortBy) => { | |||
|
|||
internals.model.orderBy(sortBy, sortDesc.indexOf(sortBy) === -1 ? 'asc' : 'desc'); | |||
internals.model.orderBy( | |||
sortBy && internals.formatRelation(sortBy), |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Not quite sure about this line, why not only pass in internals.formatRelation(sortBy)
?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
In the case where sortBy
is an empty string or null/undefined, formatRelation(sortBy)
returns modelName.
which makes the query fail.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
If that is the case, then I think we should put a conditional around the orderBy:
if (sortBy){
internals.model.orderBy(...)
}
@alechirsch Sorry for the delay, I was busy. I added the test around the sort value! |
@jamesdixon Would you be able to look at a couple of the other PRs and consider publishing a release? |
@alechirsch unfortunately, I just don't have the time. I'd be more than willing to add you as an npm publisher if you give me your npm username. Sorry I can't be more help, but I have so many other priorities at the moment. |
@jamesdixon, thanks for the offer. My npm user name is @alechirsch. |
@alechirsch you should be all set to publish. Thank you! |
Hi,
didn't work and produced the following query:
I used the
formatRelation
function so that theorder by
part is now correct:As usual, I added a test.
Cheers,