Reputation: 186
I have seen another question that technically answers what I'm answering, but my query is not working. I think the query is self explanatory but it's not returning any rows.
CakePHP find conditions with multiple 'OR'
$sector_info['Notam'] = $this->Notam->find('all', array(
'group' => 'Notam.id',
'conditions' => array(
'AND' => array(
'OR' => array(
'Notam.notam_expire_dtg < '.date("YmdHis"),
'Notam.notam_expire_dtg' => '',
),
'OR' => array(
'Notam.account_id' => $sector_info['Airport']['identifier'],
'Notam.cns_location_id' => $sector_info['Airport']['identifier'],
'Notam.account_id' => $sector_info['Airport']['icao'],
'Notam.cns_location_id' => $sector_info['Airport']['icao'],
),
),
),
)
);
I want to pull notams that are (not expired, or have no expiration) AND ( OR the other 4 conditions.
Thanks in aadvance, Ryan
EDIT: This is the query that outputs, doesn't mention Notam.notam_expire_dtg at all:
SELECT `Notam`.`id`, `Notam`.`key`, `Notam`.`source_id`, `Notam`.`account_id`, `Notam`.`notam_id`, `Notam`.`notam_nrc`, `Notam`.`xoveraccountid`, `Notam`.`xovernotamid`, `Notam`.`notam_part`, `Notam`.`cns_location_id`, `Notam`.`icao_id`, `Notam`.`icao_name`, `Notam`.`total_parts`, `Notam`.`notam_effective_dtg`, `Notam`.`notam_expire_dtg`, `Notam`.`notam_lastmod_dtg`, `Notam`.`notam_text`, `Notam`.`notam_report`, `Notam`.`notam_qcode`, `Notam`.`pull`, `Notam`.`dflag`, `Notam`.`sql_update` FROM `aaid_cake`.`notams` AS `Notam` WHERE ((`Notam`.`account_id` IN ('PABE', 'BET')) OR (`Notam`.`cns_location_id` IN ('PABE', 'BET'))) GROUP BY `Notam`.`id`
Upvotes: 0
Views: 93
Reputation: 71
Can you try this:
$sector_info['Notam'] = $this->Notam->find('all', array(
'group' => 'Notam.id',
'conditions' => array(
'OR' => array(
'Notam.notam_expire_dtg < '.date("YmdHis"),
'Notam.notam_expire_dtg' => '',
),
'AND'=>array(
'OR' => array(
'Notam.account_id' => $sector_info['Airport']['identifier'],
'Notam.cns_location_id' => $sector_info['Airport']['identifier'],
'Notam.account_id' => $sector_info['Airport']['icao'],
'Notam.cns_location_id' => $sector_info['Airport']['icao'],
)
),
),
)
);
Upvotes: 1
Reputation: 25698
php basics: You can't have duplicate array keys, your 2nd declaration of ['OR']
is overriding the first. This should make your mistake obvious.
Try this:
'conditions' => [
'AND' => [
['OR' => [/*...*/]],
['OR' => [/*.../*]]
]
]
Upvotes: 2