Search code examples
phpmagentomagento-1.5magento-1.6

Magento - To which table does getEntityTable() point?


class Mage_Sales_Model_Entity_Order_Collection extends Mage_Eav_Model_Entity_Collection_Abstract
{

    protected function _construct()
    {
        $this->_init('sales/order');
    }

    public function addItemCountExpr()
    {
        $orderTable = $this->getEntity()->getEntityTable();

        $orderItemEntityTypeId = Mage::getResourceSingleton('sales/order_item')->getTypeId();
        $this->getSelect()->join(
            array('items'=>$orderTable),
            'items.parent_id=e.entity_id and items.entity_type_id='.$orderItemEntityTypeId,
            array('items_count'=>new Zend_Db_Expr('COUNT(items.entity_id)'))
        )
        ->group('e.entity_id');
        return $this;
    }
}

Solution

  • As defined in /code/core/Mage/Sales/etc/config.xml:

    <order><table>sales_flat_order</table></order>
    

    The table for'sales/order' Model is: sales_flat_order