Object relational mapping - Relations - Join table associations - Self-referencing.php 518 Bytes
Newer Older
hansbrix's avatar
hansbrix committed
1
Self-referencing with join tables is done as follows:
2

hansbrix's avatar
hansbrix committed
3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18
<code type="php">
class User extends Doctrine_Record {
    public function setUp() {
        $this->hasMany('User as Friend','UserReference.user_id-user_id2');
    }
    public function setTableDefinition() {
        $this->hasColumn('name','string',30);
    }
}
class UserReference extends Doctrine_Record {
    public function setTableDefinition() {
        $this->hasColumn('user_id','integer');
        $this->hasColumn('user_id2','integer');
    }
}
</code>