为什么我在使用join后无法使用getCollection()或getData()?

时间:2016-08-21 19:23:28

标签: php magento

$datas = $collection->getSelect()->join(array('B' => $table), 'main_table.entity_id = B.parent_id', array());

当我尝试使用时:

$datas->getCollection();

或:

$datas->getData();

我收到此错误:

Fatal error: Uncaught exception 'Zend_Db_Select_Exception' with message 'Unrecognized method 'getData()'' in

如何在使用“join”后使用addFieldToFilter()?

1 个答案:

答案 0 :(得分:1)

因为您将Zend DB语句的结果分配给$datas变量,这将使其成为Zend_Db_Select的实例而不是集合。

您应该通过引用进行更改,而不是将其分配给您的变量。

$collection->getSelect()->join(...

然后继续使用$collection

foreach ($collection as $entity) {
    print_r($entity->getData());
}