Magento 2 Join Collection Query


Magento 2 Join Collection Query It is a little bit different to join the multiple tables with collection in magento 2 than the magento 1.x. Here in this tutorial we are going to create very simple and basic example of join in Magento 2.


Magento 2 Join Collection Query | Join Multiple Tables Example

Magento 2 Join Collection Query

Here we have created one example to join the order table with order_item table which will pull the data based on join query-

Magento 2 Join Collection Query | Example:

$objectManager =  \Magento\Framework\App\ObjectManager::getInstance();
$collection = $objectManager->get('Magento\Sales\Model\Order')->getCollection();
$collection->getSelect()->join( array('order_item'=> 'sales_order_item'), 'order_item.order_id = main_table.entity_id', array('order_item.sku')); 

On the same way you can join multiple tables.


Advertisements

Add Comment

📖 Read More