Magento left join collection Example


Magento left join collection Example : Magento left join collection query is explained below.


Magento left join collection Example

Following syntax is used for left joining two tables in magento :

//load collection 
$collection = Mage::getModel('module/model_name')->getCollection();
$collection->getSelect()->joinLeft(Mage::getConfig()->getTablePrefix().'table_to_be_joined','main_table.table_field ='.Mage::getConfig()->getTablePrefix().'table_to_be_joined.table_field',array('field_name'));

Magento left join two custom tables Example

$collection = Mage::getModel('sales/order')->getCollection();
$collection->getSelect()->joinLeft( array('order_item'=> 'sales_flat_order_item'), 'order_item.order_id = main_table.entity_id', array('order_item.sku'));

Magento 2 Left Join Example


Add Comment

📖 Read More


Advertisements