1

When 'm trying to join two tables in Magento 2, I get an empty result. This is the initial function that returns data from single table customer_entity without any error.

\Block\Account\Message\Message.php

   public function getTestCollection()
{
    $page = ($this->getRequest()->getParam('p'))? $this->getRequest()->getParam('p') : 1;
    $pageSize = ($this->getRequest()->getParam('limit'))? $this->getRequest()->getParam('limit') : 5;

    $test = $this->_test->create();

    return $collection;
}

Later I have added following lines of codes to join first table with another custom table called affiliate_account.

    $second_table_name = $this->_resource->getTableName('affiliate_account');

    $collection->getSelect()->joinLeft(array('second' => $second_table_name), 'customer_entity.entity_id =  second.customer_id');

This returns nothing and what is the correct way to join these two tables.

2
  • 1
    Confirm that you have "customer_id" into the table "affiliate_account". Sep 2, 2019 at 13:28
  • @DhirenVasoya yes. "customer_id" available in affiliate account.
    – ashanr
    Sep 2, 2019 at 14:21

0

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge that you have read and understand our privacy policy and code of conduct.

Browse other questions tagged or ask your own question.