Reputation: 906
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...
Please anybody help me to achieve this
Upvotes: 0
Views: 913
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
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