Object relational mapping - Relations - Inheritance - One table many classes.php 785 Bytes
Newer Older
hansbrix's avatar
hansbrix committed
1 2 3 4
When it comes to handling inheritance Doctrine is very smart.
In the following example we have one database table called 'entity'.
Users and groups are both entities and they share the same database table.
The only thing we have to make is 3 records (Entity, Group and User).
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


Doctrine is smart enough to know that the inheritance type here is one-table-many-classes.


<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 { }

class Group extends Entity { }
</code>