-
Notifications
You must be signed in to change notification settings - Fork 43
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
Default or custom sort not working. #88
Comments
That exception message doesn't help. If you look down the stack trace, you'll find that exception is caused by a previous exception. Can you provide details of the first exception in the stack trace, not the last? |
I can't help you unless you are able to provide the previous exception. The exception you have taken an image of is not the root cause of the problem. It is originating from here: As you can see, another exception is causing the problem. It is caught, and re-thrown as the exception you have taken an image of. However, that has a previous exception which will explain what the error is that has caused the problem. Without seeing the full stack trace - including all previous exceptions there is no way I can help you! Because I need to see the previous exceptions to know what the problem is. |
No. I need to see the entire stack trace of the exception. You've only provided part of it. If you go to the Laravel log in the Please provide the entire stack trace - not as an image, as a copy and paste of the stack trace from the Laravel log. Otherwise there is no way for me to help you, and I'll have to close the issue. |
Sure, here it is - > [2021-06-11 09:20:06] local.ERROR: Unable to encode compound document. {"userId":1,"exception":"[object] (LogicException(code: 0): Unable to encode compound document. at /home/vagrant/code/vendor/laravel-json-api/encoder-neomerx/src/Document.php:195) [previous exception] [object] (ErrorException(code: 0): asort() expects parameter 2 to be int, string given at /home/vagrant/code/vendor/laravel/framework/src/Illuminate/Collections/Collection.php:1099) |
So the error is in your log:
You should be using the $spaces->sortBy('createdAt'); That will sort by ascending order. I don't fully understand why you are sorting in the controller action like that. The If you were putting a |
Hi, Okay. Also, regarding
Please guide. |
Firstly, why are you using a custom index action? Why aren't you using the one provided by this package? If it is so you can filter by the current user, you should not need to do that yourself if you correctly follow the guidance in the Authorization chapter, particularly around using an Secondly, on the schema (and as explained in the docs) the default sort uses the JSON:API field names, not the model column names. Are you 100% sure it shouldn't be: protected $defaultSort = '-createdAt'; I.e. Also as already mentioned, if you're using a custom index action and sorting after the schema has done its work, then that will override what is on your schema. Please:
|
This issue is taking up a lot of my time, so I need to be clear: default sorting does work, and the tests prove this is case. It's tested extensively in the At the moment therefore I have no reason to suspect there's a problem with this package, and you need to look carefully at what you're doing in your application that could be causing the problem. I can't help you with that - because I can't debug what's going on in your application. |
I understand, but the defaultSort do not work for me, which is why I had to use the custom function. I tried with I have also removed the index function and used Package's results are currently showing in ascending order, which is not right. Let me know what info I need to provide further to quickly wrap this up. My request doesn't have any sort query string. Regards. |
Can you confirm you're on the latest version of the package? So the Can you confirm that it sorts by the correct order if you send the following request:
Can you also provide a copy & paste of the whole schema class? |
Can you also be clear about what you mean when you say "it is not working for me". When you have |
Your schema Your image of the request with I strongly suspect you've got an old version of the package. Please run: composer show laravel-json-api/laravel And copy & paste the output here. |
Or try fixing it as follows:
And then let me know whether it works or not. |
this solved the issue. |
I want to fetch records and it works fine, but I want to sort it with a particular column.
so I tried this in my schema -
protected $defaultSort = '-createdAt';
but this is not sorting the records, I also tried with other column names, no luck.
in my controller index function
if I use
error attached below is received. (where condition works fine, only sort is triggering that error).
I do not want to handle sort from the url like
GET /spaces?sort=-createdAt HTTP/1.1
.Please guide.
The text was updated successfully, but these errors were encountered: