3

How to convert raw php LEFT JOIN query in to magento query? What is Magentos syntax for?

Here is my query:

SELECT fieldsmanager_orders.value,sales_flat_order_address.entity_id
FROM fieldsmanager_orders
LEFT JOIN sales_flat_order_address ON fieldsmanager_orders.entity_id = sales_flat_order_address.entity_id;
3

You can call your parent collection model like

$collection = Mage::getModel('fieldsmanager/orders')->getCollection();

Note: Make sure your namespace/entity is correct.

Then from the main collection you can join the sales_flat_order_address table.

$collection->getSelect()->joinLeft(
    array('sales_flat_order_address'=>$collection->getTable('sales/order_address')),
    'main_table.entity_id=sales_flat_order_address.entity_id,
    array('*')
);

Parameters description

Here in first parameter you pass the table you want to join with.You can use an array of the format array('alias' => 'namespace/entity')

In second parameter you add your condition to join with.

and in third one you pass the columns you want from join. "*" resembles for all columns. If you want specific column you can pass in that array.

  • i have two table fieldsmanager_orders, and sales_flat_order_address – Rushikesh Solanki Jun 23 '17 at 12:58
  • Yes so this will work as above. You can load your main table collection ( fieldsmanager_orders) then you can join it with sales_flat_order_address table as shown above. – Priyank Jun 23 '17 at 13:00

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

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