Object relational mapping - Relations - Inheritance - One table one class.php 994 Bytes
Newer Older
hansbrix's avatar
hansbrix committed
1 2 3 4
In the following example we have three database tables called 'entity', 'user' and 'group'.
Users and groups are both entities.
The only thing we have to do is write 3 classes (Entity, Group and User) and make iterative
setTableDefinition method calls.
5

hansbrix's avatar
hansbrix committed
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



<code type="php">
class Entity extends Doctrine_Record { 
    public function setTableDefinition() {
        $this->hasColumn('name','string',30);
        $this->hasColumn('username','string',20);
        $this->hasColumn('password','string',16);
        $this->hasColumn('created','integer',11);
    }
}

class User extends Entity { 
    public function setTableDefinition() {
        // the following method call is needed in
        // one-table-one-class inheritance
        parent::setTableDefinition();
    }
}

class Group extends Entity {
    public function setTableDefinition() {
        // the following method call is needed in
        // one-table-one-class inheritance
        parent::setTableDefinition();
    }
}
</code>