By Engine23

Magento collection using OR for addFieldToFilter

Lets say you wanted sql that looked something like:

SELECT `main_table`.*,`main_table`.`email` AS `invitation_email`,`main_table`.`group_id` AS `invitee_group_id` FROM `enterprise_invitation` AS `main_table` WHERE ((status ='new') OR (customer_id ='1234'))

In order to achieve this, your collection needs to be formatted like this:

$collection =Mage::getModel('enterprise_invitation/invitation')->getCollection(); $collection->addFieldToFilter(array('status','customer_id'), array( array('status','eq'=>'new'), array('customer_id','eq'=>'1234')));

Now to see what this looks like you can always echo the query that this creates by using

echo $collection->getSelect()->__toString();