-
Notifications
You must be signed in to change notification settings - Fork 65
/
Relationship.class.php
58 lines (49 loc) · 1.36 KB
/
Relationship.class.php
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
<?php
/**
* A Recess Relationship is an abstraction of a foreign key relationship on the RDBMS.
*
* @author Kris Jordan <krisjordan@gmail.com>
* @copyright 2008 Kris Jordan
* @package Recess! Framework
* @license MIT
* @link http://www.recessframework.org/
*/
abstract class Relationship {
const FOREIGN_KEY = 'key';
const FOREIGN_CLASS = 'class';
const THROUGH = 'through';
const ON_DELETE = 'ondelete';
const UNSPECIFIED = 'unspecified';
const CASCADE = 'cascade';
const DELETE = 'delete';
const NULLIFY = 'nullify';
public $name;
public $localClass;
public $foreignClass;
public $foreignKey;
public $onDelete;
public $through;
abstract function getType();
abstract function init($modelClassName, $relationshipName);
function getDefaultOnDeleteMode() { return Relationship::NULLIFY; }
function delete(Model $model) {
if($this->onDelete == Relationship::UNSPECIFIED) {
$this->onDelete = $this->getDefaultOnDeleteMode();
}
switch($this->onDelete) {
case Relationship::CASCADE:
$this->onDeleteCascade($model);
break;
case Relationship::DELETE:
$this->onDeleteDelete($model);
break;
case Relationship::NULLIFY:
$this->onDeleteNullify($model);
break;
}
}
abstract function onDeleteCascade(Model $model);
abstract function onDeleteDelete(Model $model);
abstract function onDeleteNullify(Model $model);
}
?>