In this blog, we will see how to do filtering on joined column in Magento 2. We use addFieldToFilter to apply filter on collection. But the addFieldToFilter does not work if we have joined collections. Let’s suppose we have joined order collection to get the order status.
We can add the column from the second table i.e. order status for filter with addFilterToMap method like shown below,
$collection->addFilterToMap('order_status', 'order.status');
After it has been mapped we can apply filter like normal as shown below,
$collection->addFieldToFilter('order_status', 'complete');
Thanks for reading the blog. Please comment if you face any issue.