06.03 php saved
pr1001
Tags add more
associations, belongsto, habtm, model and recursive  
Note
SQL query created by findAll():

SELECT `Serviceaccount`.`id`, `Serviceaccount`.`service_id`, `Serviceaccount`.`username`, `Serviceaccount`.`password`, `Serviceaccount`.`url`, `Serviceaccount`.`supportedmedia`, `Serviceaccount`.`posttypes`, `Serviceaccount`.`created`, `Serviceaccount`.`updated`, `Service`.`id`, `Service`.`name`, `Service`.`username`, `Service`.`password`, `Service`.`url`, `Service`.`supportedmedia`, `Service`.`posttypes`, `Service`.`created`, `Service`.`updated` FROM `serviceaccounts` AS `Serviceaccount` LEFT JOIN `services` AS `Service` ON (`Serviceaccount`.`service_id` = `Service`.`id`) WHERE ((`User`.`id` IS NULL) OR (`Group`.`id` IS NULL) OR (`Event`.`id` IS NULL))
  1. <?php
  2.  
  3. // Model Serviceaccount BelongsTo Service; HABTM Event, Group, User
  4.  
  5. // app/controllers/messages_controller.php
  6. // get all appropriate serviceaccounts
  7. $conditions = array('or' => array('User.id' => $user_ids, 'Group.id' => $group_ids, 'Event.id' => $event_ids));
  8. $serviceaccounts = $this->Serviceaccount->findAll($conditions, null, null, null, null, 2);
  9.  
  10. // or
  11. $this->Serviceaccount->recursive = 2;
  12. $serviceaccounts = $this->Serviceaccount->findAll($conditions);
  13.  
  14. ?>
Parsed in 0.026 seconds, using GeSHi 1.0.7.14

Modify this Paste