-
Notifications
You must be signed in to change notification settings - Fork 2.5k
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
PersistentCollection::matching() merges orderings incorrectly when association has default sorting #7836
Comments
Thank you for reporting this issue. If you like, you can create a PR with a fix and test(s) to this issue. As far as I understand you describe a regression between two versions/commits for the orderBy behavior. But I'm not sure if there's an intended or defined behavior for a use case like this. When I read If you want to create a PR, you should aim to restore the previous known behavior you described, but I wonder if we should change it for the next major release. |
Hey @SenseException, thinking about this again I agree with you that "orderBy()" should override the default sorting. Previously (before #7766 was merged), the "->matching()" would completely ignore the I think the PersistentCollection should only use the I will try to create a PR this week. 👍 |
If no orderings are given to PersistentCollection::matching(), the orderBy annotation will be used if present. If the criteria contains orderings, those will be used without merging them with the orderBy. See doctrine#7836
If no orderings are given to PersistentCollection::matching(), the orderBy annotation will be used if present. If the criteria contains orderings, those will be used without merging them with the orderBy. See doctrine#7836
If no orderings are given to PersistentCollection::matching(), the orderBy annotation will be used if present. If the criteria contains orderings, those will be used without merging them with the orderBy. See doctrine#7836
Handled by #7850 |
Bug Report
When PersistentCollection::matching() is called with orderings, they are not correctly merged together with the default sortings of an association.
Summary
When a relationship has a default sorting configured using
@ORM\OrderBy({"lastName" = "ASC", "firstName" = "ASC"})
, the orderings are not correctly merged together with the orderings of the$criteria
in PersistentCollection::matching().Current behavior
The orderings will be sorted like the array given to the
@ORM\OrderBy
annotation, leading to unexpected results when passing another orderBy to the$criteria
of PersistentCollection::matching().How to reproduce
@ORM\OrderBy({"lastName" = "ASC", "firstName" = "ASC"})
(sort by at least 2 properties)$relationship->matching(Criteria::create()->orderBy(['firstName' => 'DESC']))
on the PersistentCollection of that relationshipExpected behavior
The collection should be ordered by
firstName DESC, lastName ASC
, but instead it will be ordered bylastName ASC, firstName DESC
.Origin of the bug
Original Issue: #7767
The bug was introduced in this PR: https://github.com/doctrine/orm/pull/7766/files#diff-108586f774fc8acb02163ed709e05e86R675
Using
$criteria->orderBy(array_merge($criteria->getOrderings(), $this->association['orderBy'] ?? [], $criteria->getOrderings()));
there would fix the ordering.The text was updated successfully, but these errors were encountered: