| 1 | <?php |
|---|
| 2 | class ClientModel extends Doctrine_Record |
|---|
| 3 | { |
|---|
| 4 | public function setTableDefinition() |
|---|
| 5 | { |
|---|
| 6 | $this->setTableName('clients'); |
|---|
| 7 | |
|---|
| 8 | $this->hasColumn('id', 'integer', 4, array('notnull' => true, |
|---|
| 9 | 'primary' => true, |
|---|
| 10 | 'autoincrement' => true, |
|---|
| 11 | 'unsigned' => true)); |
|---|
| 12 | $this->hasColumn('short_name', 'string', 32, array('notnull' => true, 'notblank', 'unique' => true)); |
|---|
| 13 | } |
|---|
| 14 | |
|---|
| 15 | public function setUp() |
|---|
| 16 | { |
|---|
| 17 | $this->hasMany('AddressModel', array('local' => 'client_id', 'foreign' => 'address_id', 'refClass' => 'ClientToAddressModel')); |
|---|
| 18 | } |
|---|
| 19 | } |
|---|
| 20 | |
|---|
| 21 | class ClientToAddressModel extends Doctrine_Record |
|---|
| 22 | { |
|---|
| 23 | public function setTableDefinition() |
|---|
| 24 | { |
|---|
| 25 | $this->setTableName('clients_to_addresses'); |
|---|
| 26 | |
|---|
| 27 | $this->hasColumn('client_id', 'integer', 11, array('primary' => true)); |
|---|
| 28 | $this->hasColumn('address_id', 'integer', 11, array('primary' => true)); |
|---|
| 29 | } |
|---|
| 30 | |
|---|
| 31 | public function construct() |
|---|
| 32 | { |
|---|
| 33 | } |
|---|
| 34 | |
|---|
| 35 | public function setUp() |
|---|
| 36 | { |
|---|
| 37 | $this->hasOne('ClientModel', array('local' => 'client_id', 'foreign' => 'id', 'onDelete' => 'CASCADE')); |
|---|
| 38 | $this->hasOne('AddressModel', array('local' => 'address_id', 'foreign' => 'id', 'onDelete' => 'CASCADE')); |
|---|
| 39 | } |
|---|
| 40 | } |
|---|
| 41 | |
|---|
| 42 | class AddressModel extends Doctrine_Record |
|---|
| 43 | { |
|---|
| 44 | public function setTableDefinition() |
|---|
| 45 | { |
|---|
| 46 | $this->setTableName('addresses'); |
|---|
| 47 | |
|---|
| 48 | $this->hasColumn('id', 'integer', 11, array('autoincrement' => true, |
|---|
| 49 | 'primary' => true |
|---|
| 50 | )); |
|---|
| 51 | $this->hasColumn('address1', 'string', 255, array('notnull' => true, 'notblank')); |
|---|
| 52 | $this->hasColumn('address2', 'string', 255, array('notnull' => true)); |
|---|
| 53 | $this->hasColumn('city', 'string', 255, array('notnull' => true, 'notblank')); |
|---|
| 54 | $this->hasColumn('state', 'string', 10, array('notnull' => true, 'notblank', 'usstate')); |
|---|
| 55 | $this->hasColumn('zip', 'string', 15, array('notnull' => true, 'notblank', 'regexp' => '/^[0-9-]*$/')); |
|---|
| 56 | } |
|---|
| 57 | |
|---|
| 58 | public function setUp() |
|---|
| 59 | { |
|---|
| 60 | $this->hasMany('ClientModel', array('local' => 'address_id', 'foreign' => 'client_id', 'refClass' => 'ClientToAddressModel')); |
|---|
| 61 | } |
|---|
| 62 | } |
|---|