Hi,
I''ve got some trouble describing the relations for my class :
I have a class named "Category" which is used to store categories and subcategories.
Subcategories are related to their parent category through a parent_category_id which is the id (in the same Category table) of the parent category.
I don't know how to overload the relations method in the model class.
I tried so far :
public function relations()
{
return array(
'subcategories'=>array(self::HAS_MANY,'Category','parent_category_id'),
'parentcategory'=>array(self::BELONGS_TO,'Category','id'),
);
}
but I'm not sure that this is the right way to do : when I try to display the parent category name in a view, using $data->parentcategory->name, I got the category name (and not the parent category name)
Any clue/advice ?
thks in advance and sorry for the bad english
Marc
Page 1 of 1
Help needed with relations describing an auto join
#2
Posted 18 February 2010 - 08:13 AM
It would be easier to help you if you post a description of your database table
Utinam ea res tibi usui fuerit!
#3
Posted 18 February 2010 - 08:38 AM
Try this:
public function relations()
{
return array(
'subcategories'=>array(self::HAS_MANY,'Category','parent_category_id'),
'parentcategory'=>array(self::BELONGS_TO,'Category','parent_category_id'),
);
}
#4
Posted 18 February 2010 - 03:25 PM
Thank you for your answers !
@Mike, your solution works perfectly ... I should have guessed (or tried) that by myself
@Daniel : here is the description (one table ...nothing simpler !)
@Mike, your solution works perfectly ... I should have guessed (or tried) that by myself
@Daniel : here is the description (one table ...nothing simpler !)
Share this topic:
Page 1 of 1

Help












