I am trying to join customer entity table and customer address entity table. I am getting error in below code.
What could be the issue
$agency_name=$customerData->getDefaultShippingAddress()->getAgencyName();
$objectManager = \Magento\Framework\App\ObjectManager::getInstance();
$resource = $objectManager->get('Magento\Framework\App\ResourceConnection');
$customerTable = $resource->getTableName('customer_entity');
$customerObj = $objectManager->create('Magento\Customer\Model\ResourceModel\Address\Collection');
$collection = $customerObj
->addAttributeToSelect('agency_name', 'customer_address_entity')
->addAttributeToFilter('agency_name',array('eq'=>$agency_name));
//->load();
$collection->getSelect()->join(['ct'=>$customerTable],'main_table.parent_id=ct.entity_id',[]);
$c_data=$collection->getData();
print_r($c_data);
Giving me error.Please Help
Best Answer
The error is because the main_table does not exist. If you debug, you can see in
the line
You must use
After this, it is not advisable to use the object manager as you are using it. For that, you can use the independence injections of the classes
and
directly in your construct.