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
[v4] sort by graphql duplicating rows #11892
Comments
Is it the same when you request data through REST API? |
I don't believe this is possible as I'm looking at the sort code and I believe sort can only be at the parent level (you can sort the relational data itself but you can't sort the parent data on the relational responses.) Looping in @strapi/maintainers here as I'm honestly not sure. |
This was working in v3 and is something I think really usefull when you want to avoid multiple queries |
Nested sorting should work. There seems to be an issue with joins that aren't distinct for some reason. that's a valid bug |
@derrickmehaffy do we have anything new on this please ? |
I haven't tested in latest versions but nothing new |
Hello @Convly, Do you have anything new on this maybe ? Thanks :) |
Hey, it's definitely something that I have in my backlog. I'll try to get at it as soon as I can, even though it'll probably be not before ~one or two weeks. Sorry for the time it's taking, I know this is quite an annoying one. |
Ok thanks for the feedback ! have a great week |
Hello, Anything new on this maybe ? |
Hey, sorry for the time it's taking and for the time it took me to answer you, I've been dealing with Typescript support for the last month and it left very little time for anything else. It's definitely something I've on my radar but I cannot promise any ETA right now. Really sorry for this situation. I'll keep you updated when I'll work on it. |
This is happening on my end too, had to manually sort in the frontend |
I have tested #13387 but it looks like it is breaking filtering on related field. What I have tried is to normalize joins and it is working for the duplication problem but is not sorting at all the nested items. Here on the join helper I have created a function where I am using joinTable and qb.state.joins to fish out an alias that could satisfy the query and avoid running the createPivotJoin function that is adding more alias and joins that potentially are causing the issue.
So I have changed the code in line 51 of the join helper into something like this...
The function looks like this
The code I have created is pretty ugly and that is because I do not know if my logic is correct in order to make it better. I am struggling to understand how strapi is handling relations and nested items. I am logging all the queries and I can see that is doing two queries when there is a relation and I have not find out yet how it is creating the nested data and if it needs the data to be flat or not. Another issue that I can see is the use of distinct in cases that should be using groupBy, Actually I believe that the groupBy is never used and there is no code that will drive execution to the place that will create grouping at the sql level through the query builder. I hope that I am not causing any confusion as I am trying to help. I have some spare time and I will continue looking into this and all the related issues hoping that someone will eventually solve that. |
The previous attempt is missing some things... is hard to test manually all the cases if there are not automated test to tell you what is effected by the changes. This needs groupBy if there is no filtering on the related field something similar with solution on #13387 given by @Bassel17 But in general the inner sorting needs more work at least when populating, so I had to add some more ugly code to try out a fix for the many to many case. I have read most of the database package and I can not find a better way to fix the sql queries as should be in my view. I do not know if what I have done is breaking something else that I have not tested. Take a look a the diff here 48d3e0e Is messy because the rest of the codebase needs some refactoring to be more friendly for an engineer to give a better solution without having to do crazy things. I am not going to make a pull request because this needs more work to be sane. I am trying to give you some hints about what I see while I have been digging on some of the database issues you have open. If you want you can check for yourselves and evaluate if this direction could give some solutions to the databases related problems. |
We are nearly coming to a year of this issue, is this fixed by any other way right now or still there ? |
@GautierDele Unfortunately, still happening on the latest version... |
@akasummer for almost a year i forgave, this wont be fixed for such a major problem. Either you find an alternative or you find another solution |
This is also a problem with the REST API, not only GraphQL. I'd call it a gamebreaker... Steps for me to reproduce: Edit: Just to make things clear… What i really would like to do is sorting my posts by its number of categories. But there is no sorting option for that why i used to make it work with categories.id in strapi v3. |
I resolved that problem by sorting items with two parameters: title which is for me sorting items and you must add sorting by id, then pagination working great.
|
This is a real problem. Why isn't this solved yet ? |
@LapX this is considered a rather complicated issue, fixing it correctly on the DB level would require a different solution for every database we support. We just didn't get the time or priority to move forward with it yet. |
Issue is still there, for example a { sort: { prices: { amount: 'asc' } }, filters: { prices: { currency: 'usd' } } } It's returning duplicated products, looks like filters are ignored, is there a way to make something like post-filtering? |
We also started experiencing this issue 2 weeks ago. So I would recommend giving a look at your lifecycle hooks if you have any. |
Same issue here. Hope that it will be fixed soon. |
Issue is there when using repeatable components as well. Can anybody suggest a solution? I cant sort manually because i have applied pagination as well and getting all the data first and then sorting and paging it would not be efficient. |
Any update on this issue ? |
same for me, any updates? |
Bug report
Describe the bug
Graphql sort on nested relations is basically duplicating rows as a join would do.
This was working in v3.
Steps to reproduce the behavior
Create your graphql query on a resource that has a relation. This is a one to many in this case, this should work for any relation i think
Call this in your sort parameters:
Expected behavior
Should only have one row per item but this is duplicated:
As you can see there i have multiples rows with the same id depending on the number of nested articles linked to the category.
System
The text was updated successfully, but these errors were encountered: