join 2 collection in custom Grid Magento.I am using the below code. I want to join with sales_flat_order to get get Shipping address & Grand Total. how to do ?

$customerId = $this->getRequest()->getParam('id');//customer Id
$collection = Mage::getModel('modulename/modelname')
    ->addFieldToFilter('customer_id', $customerId);

1 Answer 1


Please try with this:

        array('so' => $this->getTable('sales/order')),
        'main_table.order_id = so.entity_id',
        array('soa' => $this->getTable('sales/order_address')),
        "(main_table.order_id = soa.parent_id AND soa.address_type = 'shipping')",

replace order_id with the column name that you used in your table for the order ID.

Also you can view/read this - http://www.magentocommerce.com/wiki/1_-_installation_and_configuration/using_collections_in_magento .

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge that you have read and understand our privacy policy and code of conduct.

Not the answer you're looking for? Browse other questions tagged or ask your own question.