Tuesday, April 27, 2010

Re: transform query result to populate dropdown?

The cake like way to do this would be to run two queries, the first to
fetch the id's you do not want included and the second to find the
id's which do not match those your found in the first query

Please note that I write all my answers using conventions so others
viewing this later can apply it to their apps rather than it just
being pertinent to the person who was using non-conventional model/
table/field names.

Ran from Lodging model:
$first = $this->BookingPosition->find('all', array(
'fields'=>('BookingPosition.lodging_id'),
'conditions'=>array(
'BookingPosition.anreise_datum >=' => '2010-05-25 12:00:00',
'BookingPosition.abreise_datum >=' => '2010-05-30 12:00:00'
)
))
$first_ids = Set::extract('/BookingPosition/id', $first);

return $this->find('list', array(
'conditions'=>array('Lodging.id NOT IN'=>$first_ids)
))

HTH

Paul

Check out the new CakePHP Questions site http://cakeqs.org and help others with their CakePHP related questions.

You received this message because you are subscribed to the Google Groups "CakePHP" group.
To post to this group, send email to cake-php@googlegroups.com
To unsubscribe from this group, send email to
cake-php+unsubscribe@googlegroups.com For more options, visit this group at http://groups.google.com/group/cake-php?hl=en

No comments: