Want more features on Pastebin? Sign Up, it's FREE!
Guest

Untitled

By: ThievingSix on Jan 3rd, 2013  |  syntax: PHP Brief  |  size: 0.67 KB  |  views: 9  |  expires: Never
download  |  raw  |  embed  |  report abuse  |  print
Text below is selected. Please press Ctrl+C to copy to your clipboard. (⌘+C on Mac)
  1. $this->Project->contain();
  2. $this->Project->virtualFields['completion'] = '
  3.         ROUND(
  4.                 ((SUM(Todo.complete) + SUM(TodoExtra.complete)) /
  5.                 (COUNT(Todo.complete) + COUNT(TodoExtra.complete))) *
  6.                 100
  7.         )
  8. ';
  9. $projects = $this->Project->find('all', array(
  10.         'joins' => array(
  11.                 array(
  12.                         'alias' => 'Todo',
  13.                         'table' => 'project_todos',
  14.                         'type' => 'LEFT',
  15.                         'conditions' => array(
  16.                                 '`Todo`.`project_id` = `Project`.`id`',
  17.                         ),
  18.                 ),
  19.                 array(
  20.                         'alias' => 'TodoExtra',
  21.                         'table' => 'project_todo_extras',
  22.                         'type' => 'LEFT',
  23.                         'conditions' => array(
  24.                                 '`TodoExtra`.`project_id` = `Project`.`id`',
  25.                         ),
  26.                 )
  27.         ),
  28.         'group' => array(
  29.                 'Project.id',
  30.         ),
  31. ));
clone this paste RAW Paste Data