Help needed with relations describing an auto join

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

It would be easier to help you if you post a description of your database table :)

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'),

  );

}

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 !)