Object relational mapping - Relations - Relation aliases.php 900 Bytes
Newer Older
hansbrix's avatar
hansbrix committed
1
Doctrine supports relation aliases through 'as' keyword.
2

hansbrix's avatar
hansbrix committed
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
<code type="php">
class Forum_Board extends Doctrine_Record { 
    public function setTableDefinition() {
        $this->hasColumn('name', 'string', 100);
        $this->hasColumn('description', 'string', 5000);
    }
    public function setUp() {
        // notice the 'as' keyword here
        $this->ownsMany('Forum_Thread as Threads',  'Forum_Thread.board_id');
    }
}

class Forum_Thread extends Doctrine_Record {
    public function setTableDefinition() {
        $this->hasColumn('board_id', 'integer', 10);
        $this->hasColumn('updated', 'integer', 10);
        $this->hasColumn('closed', 'integer', 1);
    }
    public function setUp() {
        // notice the 'as' keyword here
        $this->hasOne('Forum_Board as Board', 'Forum_Thread.board_id');
    }
}
$board = new Board();
$board->Threads[0]->updated = time();
</code>