Changeset 2296 for trunk/manual

Show
Ignore:
Timestamp:
08/30/07 23:04:41 (17 months ago)
Author:
zYne
Message:
 
Files:
1 modified

Legend:

Unmodified
Added
Removed
  • trunk/manual/new/docs/en/mapping-relations.txt

    r2163 r2296  
    175175} 
    176176 
    177 class GroupUser extends Doctrine_Record  
     177class GroupUser extends Doctrine_Record 
    178178{ 
    179179    public function setTableDefinition()  
     
    300300 
    301301+++ One table, one class 
     302 
     303One-table-one-class inheritance is the only inheritance type that allows additional fields for inherited classes. As shown in the example above adding additional columns is very easy: 
     304 
     305<code type="php"> 
     306class TextItem extends Doctrine_Record 
     307{ 
     308    public function setTableDefinition()  
     309    { 
     310        $this->hasColumn('topic', 'string', 100); 
     311    } 
     312} 
     313 
     314class Comment extends TextItem 
     315{ 
     316    public function setTableDefinition()  
     317    { 
     318        parent::setTableDefinition();     
     319 
     320        $this->hasColumn('content', 'string', 300); 
     321    } 
     322} 
     323</code> 
     324 
     325 
     326In one-table-one-class inheritance you don't necessarily have to define additional columns, but in order to make Doctrine create separate tables for each class you'll have to make iterative setTableDefinition() calls.  
    302327 
    303328In 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.