mirror of
https://github.com/doctrine/orm.git
synced 2026-03-23 22:42:18 +01:00
PersistentCollection::matching() does not respect the collections native sorting #6266
Reference in New Issue
Block a user
Delete Branch "%!s()"
Deleting a branch is permanent. Although the deleted branch may continue to exist for a short time before it actually gets removed, it CANNOT be undone in most cases. Continue?
Originally created by @stephanschuler on GitHub (Jul 1, 2019).
Originally assigned to: @lcobucci on GitHub.
Bug Report
When PersistentCollection::matching() is called, the result in terms of sorting depends on the collection being initialized or uninitialized.
Summary
On an initialized collection, the "matching" is applied to the array content, which means sorting is basically untouched if the criteria does not provide additional sorting.
On an unitialized collection, the "matching" is queried through the database. Here the sorting of the collection isn't considered, only the sorting of the criteria is. More often than not, no predictable sorting is used here -- whenever the criteria comes without custom sorting.
Current behavior
PersistentCollection->matching(Criteria::create())without sorting doesn't use the collections sorting either.How to reproduce
@ORM/OrderBy({"name" = "ASC"})$category->getChildren()->matching(Criteria::create()).The result is not ordered according to the annotation.
Expected behavior
The result should be ordered according to the annotation.
@stephanschuler commented on GitHub (Jul 1, 2019):
First I was under the impression it's issue #6516. But that's not the case: There it's about matching not using the order of the criteria. Which is the exact opposite of what I'm experiencing.
I provided a PR with a test case.
See:
https://github.com/doctrine/orm/pull/7766
I added all of those to make sure my patch wouldn't break existing behavior.
@lcobucci commented on GitHub (Aug 13, 2019):
Handled by #7766