-
-
Notifications
You must be signed in to change notification settings - Fork 344
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
Group by is better than distinct #1319
Conversation
This post suggests that you can have issues when using pagination and no sort, but what you are saying is surprising to say the least. I would expect Can you maybe share the final SQL that is executed when you observe your bug? Also, your PR adds the |
I'm not sure what your requirements are: do you mean to display one line per contract, or should there be 2 lines if one contract happens to have 2 clients? Anyway, displaying a many-to-many in a table is not going to be simple. Maybe what you want is a |
I wanted to
In the SonataAdmin, the query is only returning an array of object, The only issue I get is with the query which is returning multiples times the same contract (which I don't want). And since the Pager returns a count different of the count of my query results, all the results are not displayed, so there is definitely something to do. |
I remembered about this issue #1225 |
The current test error is
|
483747a
to
b7e20cc
Compare
b7e20cc
to
29c2cff
Compare
29c2cff
to
1d0dd25
Compare
WDYT about also deprecating |
Ok so… we're losing a lot of information here, are we not? What's your point?
Well we can always use the id of the joined table, can we not? To me, the
Not printing ids that don't change might help the user spot that this is the There's something peculiar in the SQL request you shared:
What does that have to do with the issue at hand? My question was more about
Ok so it's the latter, you want one line, and apparently, that already works
If we are talking about the SQL query, I disagree, it's normal, that's how
You mention
Ah and now you are complaining about multiple rows… so you were talking about Overall I would instinctively favor |
I think it's best to have one line per contract. That's what I was trying to explain.
I know how a join works in SQL, I was talking about the DQL indeed.
If the contract2 has two clients, the DQL is returning something like
Both $contract2 are obviously fully hydrated. So in the Admin, I get 4 row instead of 3, and the row (of the admin list) 2 and the row (of the admin list) 4 display the same information. This is fixed with this PR, now, the result of the query is
|
49d6679
to
21db1a4
Compare
@greg0ire I'd like to find a BC way to introduce this change instead of targeting master. First, I found this one: creating a But then, I discovered that the
So the way we were fixing the queryBuilder need to be public in order to be called in the DataSource::createIterator method. WDYT about this updated PR ? :) |
667480b
to
baa80b4
Compare
bcc285d
to
da196a4
Compare
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.
Looks like a good idea 👍
b203756
to
1389ec1
Compare
This method is deprecated in SonataAdmin
Thanks @VincentLanglet ! |
Subject
I have a Contract entity and a Client entity.
A client can have multiple contracts. A contract can be associated to multiple clients.
In the
configureQuery
of myContractAdmin
, I'm using aleftJoin('contract.client')
.I got a weird behavior:
Distinct is not a good thing to use with pagination:
If the results are:
With distinct on col 1 and a limit of 2
With groupby, it's applied BEFORE the pagination, so it became
and the result are the one expected.
I tried on my project and it works.
Another thing:
setDistinct
andisDistinct
are not in the ProxyQueryInterface.I think we should deprecate them, and always adding the groupBy in the fixQueryBuilder method.
WDYT @sonata-project/contributors ?
Changelog