MIK
MIK

Reputation: 906

Creating a subcategory for Category in yii

I have certain products..now i want to create a subcategory for those product..i created a table for subcategory with category as foreign key...enter image description here

Please anybody help me to achieve this

Upvotes: 0

Views: 913

Answers (2)

JonathanStevens
JonathanStevens

Reputation: 472

You can create a model SubCategory like you did for Category, but with this relation:

public function relations()
{
    return array(
        'category' => array(self::BELONGS_TO, 'Category', 'category_id'),
    );
}

In Category you can add this relation:

public function relations()
{
    return array(
        'subCategories' => array(self::HAS_MANY, 'SubCategory', 'category_id'),
    );
}

Upvotes: 0

mo.dhouibi
mo.dhouibi

Reputation: 595

I think the best way to do it is to go to YOURDOMAIN/index.php/gii And you create your models and the relations using the interface. Thanks

Upvotes: 2

Related Questions