QueryTest_Category.php 1.11 KB
Newer Older
1 2 3 4 5 6 7 8 9 10
<?php
class QueryTest_Category extends Doctrine_Record
{    
    /**
     * The depth of the category inside the tree.
     * Non-persistent field. 
     * 
     * @var integer
     */
    public $depth;
11

12 13 14
    /**
     * Table definition.
     */
15
    public static function initMetadata($class)
16
    {        
17
        $class->setColumn('rootCategoryId as rootCategoryId', 'integer', 4,
18
                array('default' => 0));
19
        $class->setColumn('parentCategoryId as parentCategoryId', 'integer', 4,
20
                array('notnull', 'default' => 0));
21
        $class->setColumn('name as name', 'string', 50,
22
                array('notnull', 'unique'));
23
        $class->setColumn('position as position', 'integer', 4,
24
                array('default' => 0, 'notnull'));
25 26 27 28
                
        $class->hasMany('QueryTest_Category as subCategories', array('local' => 'id', 'foreign' => 'parentCategoryId'));
        $class->hasOne('QueryTest_Category as rootCategory', array('local' => 'rootCategoryId', 'foreign' => 'id'));
        $class->hasMany('QueryTest_Board as boards', array('local' => 'id', 'foreign' => 'categoryId'));
29 30
    }
}