I'm working on what I guess I would consider the very low end of a
complex find and yet I can't seem to get it quite right.
In my Alert model, I'm trying to find all of the alerts of a
particular type whose start date is null or less than NOW and whose
end date is null or greater than NOW:
return $this->find (
'list',
array (
'fields' => array ( 'Alert.message' ),
'conditions' => array (
'Alert.alert_subject_id' => strtoupper ( $subject ),
'OR' => array (
'Alert.start_date' => null,
'Alert.start_date <= ' => date ( 'Y-m-d H:i:s' )
),
'OR' => array (
'Alert.end_date' => null,
'Alert.end_date >= ' => date ( 'Y-m-d H:i:s' )
)
)
)
);
The SQL I get out seems to ignore the start_date conditions, but
includes the end_date conditions as I'd expect. If I switch the order,
then the end_date conditions are ignored and the start_date conditions
are translated to SQL as I'd expect. In my debug output, here's what I
get for this particular find() syntax (formatted for some semblance of
readability):
SELECT
`Alert`.`id`,
`Alert`.`message`
FROM `alerts` AS `Alert`
WHERE
`Alert`.`alert_subject_id` = 'TICKET'
AND (
(`Alert`.`end_date` IS NULL) OR (`Alert`.`end_date` >=
'2009-01-07 15:54:09')
)
As you can see, no mention of the start_date conditions at all. Am I
missing an array or something? Have I been looking at this too long to
see something else that's absurdly obvious? I'm using the final
release of v1.2.
Any additional eyeballs would be a much appreciated sanity check.
--~--~---------~--~----~------------~-------~--~----~
You received this message because you are subscribed to the Google Groups
"CakePHP" group.
To post to this group, send email to [email protected]
To unsubscribe from this group, send email to
[email protected]
For more options, visit this group at
http://groups.google.com/group/cake-php?hl=en
-~----------~----~----~----~------~----~------~--~---