Not a bug \XF\Mvc\Entity\AbstractCollection :: toApiResults reorders entities

DragonByte Tech

Well-known member
Affected version
2.1.0 Beta 3
Consider a query like this:

SQL:
SELECT `xf_dbtech_ecommerce_download`.*, `xf_dbtech_ecommerce_product_Product_1`.*, `xf_deletion_log_DeletionLog_2`.*
FROM `xf_dbtech_ecommerce_download`
LEFT JOIN `xf_dbtech_ecommerce_product` AS `xf_dbtech_ecommerce_product_Product_1` ON (`xf_dbtech_ecommerce_product_Product_1`.`product_id` = `xf_dbtech_ecommerce_download`.`product_id`)
LEFT JOIN `xf_deletion_log` AS `xf_deletion_log_DeletionLog_2` ON (`xf_deletion_log_DeletionLog_2`.`content_type` = 'dbtech_ecommerce_download' AND `xf_deletion_log_DeletionLog_2`.`content_id` = `xf_dbtech_ecommerce_download`.`download_id`)
WHERE (`xf_dbtech_ecommerce_download`.`product_id` = 1) AND ((`xf_dbtech_ecommerce_product_Product_1`.`product_state` IN ('visible', 'deleted', 'moderated'))) AND (`xf_dbtech_ecommerce_download`.`download_id` IN (11, 12))
ORDER BY `xf_dbtech_ecommerce_download`.`release_date` DESC

Which produces a result like this:

189385


The starting ArrayCollection is sorted correctly:

189386


Yet the final output is not:

189387

I've tested this on PHP 7.0, 7.1 and 7.2.

It's absolutely critical that you preserve the sort order when producing API results.


Fillip
 
Turns out, this is a bug in the Postman app.

190068

190069

Never would have thought that I needed to check whether syntax highlighting would reorder the things I'm seeing on the screen... 🤦‍♂️


Fillip
 
Top Bottom