FooRecord.php 3.74 KB
Newer Older
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22
<?php
class FooRecord extends Doctrine_Record
{
    public function setTableDefinition()
    {
        $this->setTableName('foo');
        
        $this->hasColumn('name', 'string', 200, array('notnull' => true));
        $this->hasColumn('parent_id', 'integer');
        $this->hasColumn('local_foo', 'integer');
    }
    public function setUp()
    {
        $this->hasMany('FooRecord as FooFriend', array('local'    => 'foo1',
                                                       'foreign'  => 'foo2',
                                                       'equal'    => true,
                                                       'refClass' => 'FooReferenceRecord',
                                                       ));

        $this->hasMany('FooRecord as FooParents', array('local'    => 'foo1',
                                                        'foreign'  => 'foo2',
                                                        'refClass' => 'FooReferenceRecord',
zYne's avatar
zYne committed
23
                                                        'onDelete' => 'RESTRICT',
24 25 26 27 28 29 30 31 32 33 34 35
                                                        ));

        $this->hasMany('FooRecord as FooChildren', array('local'    => 'foo2',
                                                         'foreign'  => 'foo1',
                                                         'refClass' => 'FooReferenceRecord',
                                                         ));

        $this->hasMany('FooRecord as Children', array('local' => 'id', 'foreign' => 'parent_id'));

        $this->hasOne('FooRecord as Parent', array('local' => 'parent_id', 'foreign' => 'id', 'onDelete' => 'CASCADE'));
        $this->hasOne('FooForeignlyOwnedWithPk', array('local' => 'id', 'foreign' => 'id', 'constraint' => true));
        $this->hasOne('FooLocallyOwned', array('local' => 'local_foo', 'onDelete' => 'RESTRICT'));
zYne's avatar
zYne committed
36 37 38 39 40
        
        $this->hasMany('BarRecord as Bar', array('local' => 'fooId',
                                                 'foreign' => 'barId',
                                                 'refClass' => 'FooBarRecord',
                                                 'onUpdate' => 'RESTRICT'));
41 42 43

    }
}
zYne's avatar
zYne committed
44 45 46 47 48 49 50 51 52 53 54
class FooReferenceRecord extends Doctrine_Record
{
    public function setTableDefinition()
    {
        $this->setTableName('foo_reference');
        
        $this->hasColumn('foo1', 'integer', null, array('primary' => true));
        $this->hasColumn('foo2', 'integer', null, array('primary' => true));
    }
}

55 56 57 58
class FooBarRecord extends Doctrine_Record
{
    public function setTableDefinition()
    {
zYne's avatar
zYne committed
59 60
        $this->hasColumn('fooId', 'integer', null, array('primary' => true));
        $this->hasColumn('barId', 'integer', null, array('primary' => true));
61 62
    }
}
zYne's avatar
zYne committed
63
class BarRecord extends Doctrine_Record
64 65 66
{
    public function setTableDefinition()
    {
zYne's avatar
zYne committed
67
    	$this->setTableName('bar');
68 69
    	$this->hasColumn('name', 'string', 200);
    }
zYne's avatar
zYne committed
70 71 72 73
    public function setUp()
    {
        $this->hasMany('FooRecord as Foo', array('local' => 'barId', 'foreign' => 'fooId', 'refClass' => 'FooBarRecord'));
    }
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
}
class FooLocallyOwned extends Doctrine_Record
{
    public function setTableDefinition()
    {
        $this->hasColumn('name', 'string', 200);
    }
}
class FooForeignlyOwned extends Doctrine_Record
{
    public function setTableDefinition()
    {
        $this->hasColumn('name', 'string', 200);
        $this->hasColumn('fooId', 'integer');
    }
}
class FooForeignlyOwnedWithPk extends Doctrine_Record
{
    public function setTableDefinition()
    {
        $this->hasColumn('name', 'string', 200);
    }
    public function setUp()
    {
        $this->hasOne('FooRecord', array('local' => 'id', 'foreign' => 'id'));
    }
}
zYne's avatar
zYne committed
101