mirror of
https://github.com/doctrine/orm.git
synced 2026-03-23 22:42:18 +01:00
Doctrine 2 Criteria using multiple orderings #4925
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 @pettersoderlund on GitHub (Dec 9, 2015).
I'm trying to order a selection created by Doctrine\Common\Collections\Criteria, http://doctrine-orm.readthedocs.org/projects/doctrine-orm/en/latest/reference/working-with-associations.html#filtering-collections with multiple order attributes as specified possible (?) in the specification of criteria
however, the collection sorted only takes notice of my first entry in the sorting array. My array of $orderings looks like
Any ideas? The docs mentions andX() in the bottom of the page linked earlier but I can't figure out how I would use it in this case.
Cheers, P
@Ocramius commented on GitHub (Dec 10, 2015):
I think this is a genuine bug that requires a failing test case.
@koprivajakub commented on GitHub (Dec 15, 2015):
I have easy fix for this. Could you assign this to me? I need to solve it :)
@pettersoderlund commented on GitHub (Dec 19, 2015):
Whats the ETA on fixing this you'd think @Ocramius ? Need to consider changing strategy or not :)
@billschaller commented on GitHub (Dec 19, 2015):
@pettersoderlund If you can provide a test case it should be easy enough to fix. Ocramius is on holiday till the 24th.
@pettersoderlund commented on GitHub (Dec 19, 2015):
@zeroedin-bill thanks for getting back so quickly!
I did not really figure out where to put a relevant test case but found some changes that might sort it out (pun intended). In the file /doctrine/collections/lib/Doctrine/Common/Collections/ArrayCollection.php
I made the following changes from line 370 according to the comments:
@pettersoderlund commented on GitHub (Dec 20, 2015):
Gave a shot at a test case in (that is atm failing) collections/tests/Doctrine/Tests/Common/Collections/ArrayCollectionTest.php
@webjoaoneto commented on GitHub (Mar 15, 2016):
This code fixed this bug for me:
foreach (array_reverse($orderings) as $field => $ordering) { $next = ClosureExpressionVisitor::sortByField($field, $ordering == Criteria::DESC ? -1 : 1, $next ); }@MalteHillmann commented on GitHub (Mar 21, 2016):
Thank you @joao-gsneto , your code works fine.
I hope this will soon be fixed in the official doctrine release.
@cdaguerre commented on GitHub (Feb 10, 2017):
This was actually fixed in v1.4.0 by
4b1e0f4682,but is it expected that the indexes are not updated?
As a result, calling
Collection::offsetGet()orCollection::indexOf()after sorting still returns items/indexes before sorting...@guaycuru commented on GitHub (Nov 26, 2020):
Is there an open issue for that @cdaguerre ? I've just come across this (more than 3 years old) problem...
@tautis154 commented on GitHub (Dec 10, 2024):
How is this still not fixed and occurring.
@greg0ire commented on GitHub (Dec 10, 2024):
@tautis154 as mentioned by @cdaguerre in 2017, this has been fixed for years.