I'm having some trouble mapping a SQL query to the "Varien syntax".
So, I have a table where two of the columns are 'week' and 'year'. Now I want to grab a collection of data from that table where I want to go from the "current week number" (pre-calculated) in the current year (2015) AND from week 1 to week 52 on 2016.
For now, I have this query:
$deliveryDeviations = Mage::getModel('godtlevert/delivery_deviation')->getCollection()
->AddFieldToSelect('*')
->AddFieldToFilter('billing_agreement_id', array('eq' => $billingAgreement->getId()))
->AddFieldToFilter(
array(
array('week', array('in' => $totalWeeks)),
array('year', array('eq' => $year))
)
)
->AddFieldToFilter(
array(
array('week', array('from' => '1', 'to' => '52')),
array('year', array('eq' => '2016'))
)
)
But this doesn't seem to be working as expected since it's placing ORs and I want the following:
WHERE (week IN (35,36,...) AND year = 2015)
OR (week IN (1,2,...,52) AND year = 2016)
Where am I going wrong?
addFieldToFilter
, only the other way around (see: magento.stackexchange.com/questions/96930/…) - so you have to manipulate the select object directly (like in the answer by @MagePsycho)