3

I need to make a inner join between my custom table and one of Magento's entity tables.. how can i do this with Magento's ORM model?

Thanks a lot in advance.

Jonathan Day
  • 18,519
  • 10
  • 84
  • 137
balanv
  • 10,686
  • 27
  • 91
  • 137

1 Answers1

3

Read through the official API documentation and review the joinTable, joinField and joinAttribute methods.

Here is an example for joining tables related to the Orders collection:

$this->_orders = Mage::getResourceModel('sales/order_collection')
        ->addAttributeToSelect('*')
        ->joinAttribute('billing_firstname', 'order_address/firstname', 'billing_address_id', null, 'left')
        ->joinAttribute('billing_lastname', 'order_address/lastname', 'billing_address_id', null, 'left')
        ->joinAttribute('billing_street', 'order_address/street', 'billing_address_id', null, 'left')
        ->joinAttribute('billing_company', 'order_address/company', 'billing_address_id', null, 'left')
        ->joinAttribute('billing_city', 'order_address/city', 'billing_address_id', null, 'left')
        ->joinAttribute('billing_region', 'order_address/region', 'billing_address_id', null, 'left')
        ->joinAttribute('billing_country', 'order_address/country_id', 'billing_address_id', null, 'left')
        ->joinAttribute('shipping_firstname', 'order_address/firstname', 'shipping_address_id', null, 'left')
        ->joinAttribute('shipping_lastname', 'order_address/lastname', 'shipping_address_id', null, 'left')
        ->joinAttribute('shipping_street', 'order_address/street', 'shipping_address_id', null, 'left')
        ->joinAttribute('shipping_company', 'order_address/company', 'shipping_address_id', null, 'left')
        ->joinAttribute('shipping_telephone', 'order_address/telephone', 'shipping_address_id', null, 'left')
        ->joinAttribute('shipping_fax', 'order_address/fax', 'shipping_address_id', null, 'left');

You should also review this question for examples of what has been tried and their effects.

HTH,
JD

Community
  • 1
  • 1
Jonathan Day
  • 18,519
  • 10
  • 84
  • 137