I have tried to search this forum, the docs, and well, just about every source for my particular issue, but I have, unfortunately, found none.
So, this is my question: I currently have a use-case where a parent object has a date, but I need to display the children of all parent objects in a table. But when a user selects sorting by date, the child objects should be sorted accordingly.
Now, I haven’t found an option to sort a listing by parent key, but I did find a MySQL solution for that which, obviously doesn’t work since Listing()->orderKey() only supports fields, not functions as well.
To put it in an example, I have a bunch of objects of class A (let’s say that the identifier is 100), which have a date in them. Class B (identifier is 101, for example) is the child class. So, a MySQL query would look like this in my case (considering I’ve already made a listing of class A, and got the parentId list based on it - ordered by date - let’s say that this is the list - [32, 25, 58]):
select * from object_101 where o_parentId in (32,25,58) order by find_in_set(o_parentId, '32,25,58');
When I make a listing like so:
$BListing = new DataObject\BClass\Listing();
$BListing->setCondition('o_parentId in (' . implode(',', [32,25,58]) . ')');
I, of course, get an arbitrary order. So, what should go into $BListing->setOrderKey() for my particular use-case to work?