Reis mit Eis Reis mit Eis - 3 months ago 12
PHP Question

why I cant use getCollection() or getData() after using join?

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


when I try to use:

$datas->getCollection();


or:

$datas->getData();


I am getting this error:

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


and how can I use addFieldToFilter() after using a "join"?

Answer

Because you're assigning the result of a Zend DB statement to your $datas variable, which would make it an instance of Zend_Db_Select rather than a collection.

You should just make changes by reference rather than assigning it to your variable.

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

Then continue to use $collection:

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