I tried $this->Incident->find('all', array('conditions' => array('DATE_FORMAT(Detail.comment_date, \'%Y-%m-%d\') < Incident.exp_date'))); and Cake give me an error "SQL Error: 1054: Unknown column 'Detail.comment_date' in 'where clause'". And it's absolutely correct because sql query is "SELECT `Incident`.`id`, `Incident`.`start_date`, `Incident`.`exp_date`, `Incident`.`incoming_num`, `Incident`.`incoming_date` FROM `incidents` AS `Incident` WHERE DATE_FORMAT(`Detail`.`comment_date`, '%Y-%m-%d') < `Incident`.`exp_date`" i tried to use joins and it's solved this problem, but how I can select row in Detail exactly with last comment_id. I tried this: $b = array( array('table' => 'incidents', 'alias' => 'Incident1', 'type' => 'INNER', 'conditions' => array('Detail.incident_id = Incident1.id', 'Incident1.exp_date > DATE_FORMAT(Detail.comment_date, \'%Y-%m-%d\')') ) ); $this->Incident->Detail->find('all', array('joins' => $b));
On 30 июн, 21:24, Dominik Gajewski <dominikgajews...@gmail.com> wrote: > Why don't you try to create next condition in your query, > 'Detail.comment_date < Incident.exp_date' > > 2011/6/30 Quarck <quarcks...@gmail.com>: > > > > > > > [0] => Array > > ( > > [Incident] => Array > > ( > > [id] => 37 > > [start_date] => 2010-10-08 > > [exp_date] => 2010-10-14 > > [incoming_num] => 453-10 > > [incoming_date] => 2010-10-08 > > ) > > [Detail] => Array > > ( > > [0] => Array > > ( > > [id] => 98 > > [incident_id] => 37 > > [comment_id] => 1 > > [comment_date] => 2010-10-11 10:07:29 > > [notify_only] => 0 > > ) > > [1] => Array > > ( > > [id] => 99 > > [incident_id] => 37 > > [comment_id] => 2 > > [comment_date] => 2010-10-11 17:01:09 > > [notify_only] => 0 > > ) > > [2] => Array > > ( > > [id] => 100 > > [incident_id] => 37 > > [comment_id] => 3 > > [comment_date] => 2010-10-12 09:08:01 > > [notify_only] => 0 > > ) > > ) > > ) > > [1] => Array > > How can I select only those Incident.id, whose last Detail.comment_date < > > Incident.exp_date? Is it possible to compare in cakephp fields from > > different tables? Thans as advance for any assistant. > > > -- > > Our newest site for the community: CakePHP Video Tutorials > >http://tv.cakephp.org > > Check out the new CakePHP Questions sitehttp://ask.cakephp.organd help > > others with their CakePHP related questions. > > > To unsubscribe from this group, send email to > > cake-php+unsubscr...@googlegroups.com For more options, visit this group at > >http://groups.google.com/group/cake-php > > -- > Pozdrawiam > Dominik Gajewski -- Our newest site for the community: CakePHP Video Tutorials http://tv.cakephp.org Check out the new CakePHP Questions site http://ask.cakephp.org and help others with their CakePHP related questions. To unsubscribe from this group, send email to cake-php+unsubscr...@googlegroups.com For more options, visit this group at http://groups.google.com/group/cake-php