2014-01-30 1 views
1

이 코드는 그리드에 있습니다. order 및 order_address에서 일부 필드를 검색하려고합니다. 내가 쿼리에서 볼 수Magento에서 오류가 발생했습니다.

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` 

: LEFT JOIN '' AS 'order' 내 조인 생성이 SQL 쿼리를 얻고있다. 그건 맞지 않아. 다음은 쿼리가 생성되는 코드입니다. 어떤 도움도 환영합니다.

$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'); 

답변

0

내가 마지막으로 다음과 같이 일반 테이블 이름을 사용하여 그것을 해결 :

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

Mage_Adminhtml_Block_Report_Grid를 확장하는 클래스

$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'); 
0

는 젠토의 핵심 사용은 테이블 이름을 얻기 위해 밑줄 이것에 만족하지 않지만 작동합니다.

+0

죄송합니다. 작동하지 않았습니다. – reydelleon

관련 문제