Sample::afterFind()   A
last analyzed

Complexity

Conditions 3
Paths 3

Size

Total Lines 21

Duplication

Lines 0
Ratio 0 %

Importance

Changes 0
Metric Value
dl 0
loc 21
rs 9.584
c 0
b 0
f 0
cc 3
nc 3
nop 2
1
<?php
2
class Sample extends AppModel {
3
4
	public $belongsTo = array('Apple');
5
6
/**
7
 * afterFind
8
 *
9
 * @param array $results Results
10
 * @param bool $primary Primary
11
 * @return array
12
 */
13
	public function afterFind($results, $primary = false) {
14
		foreach ($results as &$result) {
15
			$apple = $this->Apple->find('first', array(
16
				'fields' => array(
17
					'Apple.id',
18
					'Apple.apple_id',
19
				),
20
				'contain' => array(
21
					'ParentApple' => array('fields' => array('id', 'name')),
22
				),
23
				'conditions' => array('Apple.id' => $result[$this->alias]['id']),
24
			));
25
26
			if ($apple) {
27
				$apple = $apple['Apple'] + $apple;
28
				unset($apple['Apple']);
29
			}
30
			$result[$this->alias]['Apple'] = $apple;
31
		}
32
		return $results;
33
	}
34
}
35