Friday, March 11, 2011

Merge two collections in Magento

Searched for the way to merge two Magento collections. Here is the interesting approach I've figured out. We can extract SELECT object from both collections and then use UNION to merge the results of these collections.

$selectFoo = Mage::getResourceModel('model/foo')->getSelect();
$selectBar= Mage::getResourceModel('model/bar')->getSelect();

$mergedFooBar = $selectFoo->union(array($selectBar));

Quick and dirty but anyway possibly someone can suggest any alternative solution?