简体   繁体   中英

Join collection query not working in Magento

I have problem in join Collection in Magento. When i echo my query there is main_table instead of product. Here is my query and

SELECT `main_table`.*, `cat`.`name` FROM `product` AS `main_table` INNER JOIN `` AS `cat` ON product.cat_id = cat.id

Block with Action name getProductData().

public function getProductData()
{
         $collection = Mage::getModel('web/product')->getCollection();
         $collection->getSelect()->joinInner( array('cat'=>$this->getTable('web/web')), 'product.cat_id = cat.id', array('name'));
         //echo $collection->getSelect(); die;
         return $collection;
}

What i need to change in that action ? Any help will be appreciated.

That's normal to consider the product table as main_table in collection but your function $this->getTable('web/web') is not returning the table name. You can try by using a static name of that table for testing. Or use Mage::getSingleton('core/resource')->getTableName('web/web'); instead of $this->getTable('web/web') .

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM