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
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
<?php
/**
* Doctrine_TicketNjero_TestCase
*
* @package Doctrine
* @author Jeff Rafter <lists@jeffrafter.com>
* @license http://www.opensource.org/licenses/lgpl-license.php LGPL
* @category Object Relational Mapping
* @link www.phpdoctrine.com
* @since 1.0
* @version $Revision$
*/
class CoverageCodeN extends Doctrine_Record {
public function setTableDefinition(){
$this->setTableName('coverage_codes');
$this->hasColumn('id', 'integer', 4, array('notnull' => true, 'primary' => true, 'autoincrement' => true));
$this->hasColumn('code', 'integer', 4, array ( 'notnull' => true, 'notblank' => true,));
$this->hasColumn('description', 'string', 4000, array ( 'notnull' => true, 'notblank' => true,));
}
public function setUp(){
# $this->index('code', array('fields' => 'code'));
}
}
class PolicyCodeN extends Doctrine_Record {
public function setTableDefinition(){
$this->setTableName('policy_codes');
$this->hasColumn('id', 'integer', 4, array('notnull' => true, 'primary' => true, 'autoincrement' => true));
$this->hasColumn('code', 'integer', 4, array ( 'notnull' => true, 'notblank' => true,));
$this->hasColumn('description', 'string', 4000, array ( 'notnull' => true, 'notblank' => true,));
}
public function setUp(){
# $this->index('code', array('fields' => 'code'));
}
}
class LiabilityCodeN extends Doctrine_Record {
public function setTableDefinition(){
$this->setTableName('liability_codes');
$this->hasColumn('id', 'integer', 4, array('notnull' => true, 'primary' => true, 'autoincrement' => true));
$this->hasColumn('code', 'integer', 4, array ( 'notnull' => true, 'notblank' => true,));
$this->hasColumn('description', 'string', 4000, array ( 'notnull' => true, 'notblank' => true,));
}
public function setUp(){
# $this->index('code', array('fields' => 'code'));
}
}
class PolicyN extends Doctrine_Record {
public function setTableDefinition(){
$this->setTableName('policies');
$this->hasColumn('id', 'integer', 4, array('notnull' => true, 'primary' => true, 'autoincrement' => true));
$this->hasColumn('rate_id', 'integer', 4, array ( ));
$this->hasColumn('policy_number', 'integer', 4, array ( 'unique' => true, ));
}
public function setUp(){
$this->hasOne('RateN', array('local' => 'rate_id', 'foreign' => 'id' ));
}
}
class RateN extends Doctrine_Record{
public function setTableDefinition(){
$this->setTableName('rates');
$this->hasColumn('id', 'integer', 4, array('notnull' => true, 'primary' => true, 'autoincrement' => true));
$this->hasColumn('policy_code', 'integer', 4, array ( 'notnull' => true, 'notblank' => true,));
$this->hasColumn('coverage_code', 'integer', 4, array ( 'notnull' => true, 'notblank' => true,));
$this->hasColumn('liability_code', 'integer', 4, array ( 'notnull' => true, 'notblank' => true,));
$this->hasColumn('total_rate', 'float', null, array ( 'notnull' => true, 'notblank' => true,));
}
public function setUp(){
# $this->index('policy_code_idx', array('fields' => 'policy_code'));
# $this->index('coverage_code_idx', array('fields' => 'coverage_code'));
# $this->index('liability_code_idx', array('fields' => 'liability_code'));
$this->hasOne('PolicyCodeN', array('local' => 'policy_code', 'foreign' => 'code' ));
$this->hasOne('CoverageCodeN', array('local' => 'coverage_code', 'foreign' => 'code' ));
$this->hasOne('LiabilityCodeN', array('local' => 'liability_code', 'foreign' => 'code' ));
}
}
class Doctrine_TicketNjero_TestCase extends Doctrine_UnitTestCase
{
public function prepareData() { }
public function prepareTables()
{
$this->tables[] = 'CoverageCodeN';
$this->tables[] = 'PolicyCodeN';
$this->tables[] = 'LiabilityCodeN';
$this->tables[] = 'PolicyN';
$this->tables[] = 'RateN';
parent::prepareTables();
}
public function testHasOneMultiLevelRelations()
{
$policy_code = new PolicyCodeN();
$policy_code->code = 1;
$policy_code->description = "Special Policy";
$policy_code->save();
$coverage_code = new CoverageCodeN();
$coverage_code->code = 1;
$coverage_code->description = "Full Coverage";
$coverage_code->save();
$liability_code = new LiabilityCodeN();
$liability_code->code = 1;
$liability_code->description = "Limited Territory";
$liability_code->save();
$rate = new RateN();
$rate->policy_code = 1;
$rate->coverage_code = 1;
$rate->liability_code = 1;
$rate->total_rate = 123.45;
$rate->save();
$policy = new PolicyN();
$policy->rate_id = 1;
$policy->policy_number = "123456789";
$policy->save();
$q = new Doctrine_Query();
$p = $q->from("PolicyN p")
->where("p.id = 1")
->execute()
->getFirst();
$this->assertEqual($p->rate_id, 1);
$this->assertEqual($p->RateN->id, 1);
}
}?>