Apple::__construct()   A
last analyzed

Complexity

Conditions 1
Paths 1

Size

Total Lines 9
Code Lines 6

Duplication

Lines 0
Ratio 0 %

Importance

Changes 0
Metric Value
dl 0
loc 9
rs 9.6666
c 0
b 0
f 0
cc 1
eloc 6
nc 1
nop 3
1
<?php
2
class Apple extends AppModel {
0 ignored issues
show
Coding Style Compatibility introduced by
PSR1 recommends that each class must be in a namespace of at least one level to avoid collisions.

You can fix this by adding a namespace to your class:

namespace YourVendor;

class YourClass { }

When choosing a vendor namespace, try to pick something that is not too generic to avoid conflicts with other libraries.

Loading history...
3
4
	public $belongsTo = array(
5
		'ParentApple' => array(
6
			'className' => 'Apple',
7
			'foreignKey' => 'apple_id'
8
		)
9
	);
10
11
	public $hasOne = array(
12
		'SampleA' => array(
13
			'className' => 'Sample',
14
			'conditions' => array(
15
				'SampleA.id' => 1,
16
			),
17
			'external' => true,
18
		),
19
	);
20
21
	public $hasMany = array(
22
		'Sample'
23
	);
24
25
/**
26
 * Constructor
27
 *
28
 * @param mixed $id ID
29
 * @param string $table Table
30
 * @param string $ds DataSource
31
 */
32
	public function __construct($id = false, $table = null, $ds = null) {
33
		parent::__construct($id, $table, $ds);
34
35
		$this->hasOne['NextApple'] = array(
36
			'className' => 'Apple',
37
			'foreignKey' => 'apple_id',
38
			'finderQuery' => $this->getNextAppleFinderQuery(),
39
		);
40
	}
41
42
/**
43
 * Finder query for NextApple
44
 *
45
 * @return string
46
 */
47
	public function getNextAppleFinderQuery() {
48
		$db = $this->getDataSource();
49
50
		return $db->buildStatement(
51
			array(
52
				'fields' => $db->fields($this, 'NextApple', array('id', 'apple_id', 'name', 'color', 'created', 'modified')),
53
				'alias' => 'NextApple',
54
				'table' => $db->fullTableName($this),
55
				'conditions' => array(
56
					'id >' => '{$__cakeID__$}',
57
				),
58
				'limit' => 1,
59
			),
60
			$this
61
		);
62
	}
63
}
64