1
0
mirror of synced 2024-12-13 22:56:04 +03:00
This commit is contained in:
zYne 2007-06-24 18:40:42 +00:00
parent 2206476d55
commit 04bca791bc

View File

@ -1,15 +1,18 @@
<?php <?php
class Entity extends Doctrine_Record { class Entity extends Doctrine_Record
public function setUp() { {
$this->ownsOne('Email', 'Entity.email_id'); public function setUp()
$this->ownsMany('Phonenumber', 'Phonenumber.entity_id'); {
$this->ownsOne('Account', 'Account.entity_id'); $this->ownsOne('Email', array('local' => 'email_id'));
$this->ownsMany('Phonenumber', array('foreign' => 'entity_id'));
$this->ownsOne('Account', array('foreign' => 'entity_id'));
$this->hasMany('Entity', array('local' => 'entity1', $this->hasMany('Entity', array('local' => 'entity1',
'refClass' => 'EntityReference', 'refClass' => 'EntityReference',
'foreign' => 'entity2', 'foreign' => 'entity2',
'equal' => true)); 'equal' => true));
} }
public function setTableDefinition() { public function setTableDefinition()
{
$this->hasColumn('id', 'integer',20, 'autoincrement|primary'); $this->hasColumn('id', 'integer',20, 'autoincrement|primary');
$this->hasColumn('name', 'string',50); $this->hasColumn('name', 'string',50);
$this->hasColumn('loginname', 'string',20, array('unique')); $this->hasColumn('loginname', 'string',20, array('unique'));
@ -21,8 +24,10 @@ class Entity extends Doctrine_Record {
$this->option('subclasses',array('User','Group')); $this->option('subclasses',array('User','Group'));
} }
} }
class FieldNameTest extends Doctrine_Record { class FieldNameTest extends Doctrine_Record
public function setTableDefinition() { {
public function setTableDefinition()
{
$this->hasColumn('someColumn', 'string', 200, array('default' => 'some string')); $this->hasColumn('someColumn', 'string', 200, array('default' => 'some string'));
$this->hasColumn('someEnum', 'enum', 4, array('default' => 'php', 'values' => array('php', 'java', 'python'))); $this->hasColumn('someEnum', 'enum', 4, array('default' => 'php', 'values' => array('php', 'java', 'python')));
$this->hasColumn('someArray', 'array', 100, array('default' => array())); $this->hasColumn('someArray', 'array', 100, array('default' => array()));
@ -30,30 +35,40 @@ class FieldNameTest extends Doctrine_Record {
$this->hasColumn('someInt', 'integer', 20, array('default' => 11)); $this->hasColumn('someInt', 'integer', 20, array('default' => 11));
} }
} }
class EntityReference extends Doctrine_Record { class EntityReference extends Doctrine_Record
public function setTableDefinition() { {
public function setTableDefinition()
{
$this->hasColumn('entity1', 'integer', null, 'primary'); $this->hasColumn('entity1', 'integer', null, 'primary');
$this->hasColumn('entity2', 'integer', null, 'primary'); $this->hasColumn('entity2', 'integer', null, 'primary');
//$this->setPrimaryKey(array('entity1', 'entity2')); //$this->setPrimaryKey(array('entity1', 'entity2'));
} }
} }
class Account extends Doctrine_Record { class Account extends Doctrine_Record
public function setTableDefinition() { {
public function setTableDefinition()
{
$this->hasColumn('entity_id', 'integer'); $this->hasColumn('entity_id', 'integer');
$this->hasColumn('amount', 'integer'); $this->hasColumn('amount', 'integer');
} }
} }
class EntityAddress extends Doctrine_Record { class EntityAddress extends Doctrine_Record
public function setTableDefinition() { {
$this->hasColumn('user_id', 'integer'); public function setTableDefinition()
$this->hasColumn('address_id', 'integer'); {
$this->hasColumn('user_id', 'integer', null, array('primary' => true));
$this->hasColumn('address_id', 'integer', null, array('primary' => true));
} }
} }
class Address extends Doctrine_Record { class Address extends Doctrine_Record
public function setUp() { {
$this->hasMany('User', 'Entityaddress.entity_id'); public function setUp()
{
$this->hasMany('User', array('local' => 'user_id',
'foreign' => 'address_id',
'refClass' => 'EntityAddress'));
} }
public function setTableDefinition() { public function setTableDefinition() {
$this->hasColumn('address', 'string', 200); $this->hasColumn('address', 'string', 200);
@ -88,28 +103,35 @@ class Description extends Doctrine_Record {
} }
} }
class UserTable extends Doctrine_Table { } class UserTable extends Doctrine_Table { }
class User extends Entity { class User extends Entity
public function setUp() { {
public function setUp()
{
parent::setUp(); parent::setUp();
$this->hasMany('Address', 'Entityaddress.address_id'); $this->hasMany('Address', array('local' => 'user_id',
'foreign' => 'address_id',
'refClass' => 'EntityAddress'));
$this->ownsMany('Album', 'Album.user_id'); $this->ownsMany('Album', 'Album.user_id');
$this->ownsMany('Book', 'Book.user_id'); $this->ownsMany('Book', 'Book.user_id');
$this->hasMany('Group', 'Groupuser.group_id'); $this->hasMany('Group', 'Groupuser.group_id');
$this->option('inheritanceMap', array('type' => 0)); $this->option('inheritanceMap', array('type' => 0));
} }
/** Custom validation */ /** Custom validation */
public function validate() { public function validate()
{
// Allow only one name! // Allow only one name!
if ($this->name !== 'The Saint') { if ($this->name !== 'The Saint') {
$this->errorStack()->add('name', 'notTheSaint'); $this->errorStack()->add('name', 'notTheSaint');
} }
} }
public function validateOnInsert() { public function validateOnInsert()
{
if ($this->password !== 'Top Secret') { if ($this->password !== 'Top Secret') {
$this->errorStack()->add('password', 'pwNotTopSecret'); $this->errorStack()->add('password', 'pwNotTopSecret');
} }
} }
public function validateOnUpdate() { public function validateOnUpdate()
{
if ($this->loginname !== 'Nobody') { if ($this->loginname !== 'Nobody') {
$this->errorStack()->add('loginname', 'notNobody'); $this->errorStack()->add('loginname', 'notNobody');
} }
@ -117,7 +139,8 @@ class User extends Entity {
} }
class SelfRefTest extends Doctrine_Record class SelfRefTest extends Doctrine_Record
{ {
public function setTableDefinition() { public function setTableDefinition()
{
$this->hasColumn('name', 'string', 50); $this->hasColumn('name', 'string', 50);
$this->hasColumn('created_by', 'integer'); $this->hasColumn('created_by', 'integer');
} }
@ -126,20 +149,25 @@ class SelfRefTest extends Doctrine_Record
$this->hasOne('SelfRefTest as createdBy', array('local' => 'created_by')); $this->hasOne('SelfRefTest as createdBy', array('local' => 'created_by'));
} }
} }
class Groupuser extends Doctrine_Record { class Groupuser extends Doctrine_Record
public function setTableDefinition() { {
public function setTableDefinition()
{
$this->hasColumn('added', 'integer'); $this->hasColumn('added', 'integer');
$this->hasColumn('group_id', 'integer'); $this->hasColumn('group_id', 'integer');
$this->hasColumn('user_id', 'integer'); $this->hasColumn('user_id', 'integer');
} }
} }
class Phonenumber extends Doctrine_Record { class Phonenumber extends Doctrine_Record
public function setTableDefinition() { {
public function setTableDefinition()
{
$this->hasColumn('phonenumber', 'string',20); $this->hasColumn('phonenumber', 'string',20);
$this->hasColumn('entity_id', 'integer'); $this->hasColumn('entity_id', 'integer');
} }
public function setUp() { public function setUp()
$this->hasOne('Entity', 'Phonenumber.entity_id'); {
$this->hasOne('Entity', array('local' => 'entity_id'));
} }
} }
@ -153,8 +181,10 @@ class Element extends Doctrine_Record {
$this->hasOne('Element as Parent', 'Element.parent_id'); $this->hasOne('Element as Parent', 'Element.parent_id');
} }
} }
class Email extends Doctrine_Record { class Email extends Doctrine_Record
public function setTableDefinition() { {
public function setTableDefinition()
{
$this->hasColumn('address', 'string', 150, 'email|unique'); $this->hasColumn('address', 'string', 150, 'email|unique');
} }
} }