Magento连接中出错

Magento连接中出错,magento,join,grid,admin,Magento,Join,Grid,Admin,我的网格中有这个代码。我正在尝试从订单和订单地址中检索一些字段。我正在为我的加入生成以下sQL查询: SELECT `main_table`.`region`, `main_table`.`city`, `order`.* FROM `sales_flat_order_address` AS `main_table` LEFT JOIN `` AS `order` ON order.entity_id = main_table.parent_id WHERE (address_type = 's

我的网格中有这个代码。我正在尝试从订单和订单地址中检索一些字段。我正在为我的加入生成以下sQL查询:

SELECT `main_table`.`region`, `main_table`.`city`, `order`.* FROM `sales_flat_order_address` AS `main_table` LEFT JOIN `` AS `order` ON order.entity_id = main_table.parent_id WHERE (address_type = 'shipping') AND (region = 'California') GROUP BY `city`
我可以在查询中看到这一点:左连接为“order”。那是不对的。下面是生成查询的代码。欢迎任何帮助

    $collection = Mage::getModel('sales/order_address')->getCollection();
    $collection
        ->addAttributeToSelect('region')
        ->addAttributeToSelect('city')
        ->addAttributeToFilter('address_type', 'shipping')
        ->addAttributeToFilter('region', 'California');

    $collection->getSelect()->joinLeft(
        array('order' => $this->getTable('sales/order')),//The problem is here!
        'order.entity_id = main_table.parent_id',
        array('order.*'))
        ->group('city');
在扩展Mage_Adminhtml_Block_Report_网格的类中,Magento的核心使用下划线获取表名:

$coreResource = Mage::getSingleton('core/resource');
$collection = Mage::getModel('sales/order_address')->getCollection();
$collection
    ->addAttributeToSelect('region')
    ->addAttributeToSelect('city')
    ->addAttributeToFilter('address_type', 'shipping')
    ->addAttributeToFilter('region', 'California');

$collection->getSelect()->joinLeft(
    array('order' => $this->getTable('sales_order')),
    'order.entity_id = main_table.parent_id',
    array('order.*'))
    ->group('city');

我最终用简单的表名解决了这个问题,如下所示:

$collection->getSelect()->joinLeft(
        array('order' => 'sales_flat_order'),
        'order.entity_id = main_table.parent_id',
        array('order.*'))
        ->group('city');
对此不满意,但它起作用了