I have 2 entities : Events and Cards they both have a 'position'
field and I want to retrieve them all and sort them by position in an array.
So I would get something like:
array('Card_1 (position 1)', 'Event_3 (position 2)', 'Event 2 (position 3)', 'Card 2 (position 4)')
and so on.
Normally I would use something like a UNION
in Native SQL, is there a simpler way to do that using Doctrine ?
I couldn't use a Native Query as it was getting me cardinality issues and using a mapped superclass wasn't an option as this type of class cannot be query-ied.
I retrieved both set of entities separately, merged the array and used usort to do the job:
$result = array_merge($events, $cards);
usort($result, function($a, $b) { return strcmp($a->getPosition(), $b->getPosition()); });
If anyone came up with a better solution using Doctrine I am curious to see it.