Relation AR

Hello all,

I am creating my back office for managing my CV.

The table is as follow:

cv_category

–>id_cv_category

–>title

cv_language

–>id_language

–>language

cv_text

–>id_cv_category

–>id_language

–>text

So I set up :

In cv_category model:

'id_cv_category'=>array(self::HAS_MANY,'cv_text','id_cv_category')

In cv_text model:

'id_cv_category'=>array(self::BELONGS_TO,'cv_category','id_cv_category'),

When I am trying to retrieve all category from cv_text controler:

$cv_texte = new cv_texte;


$criteria = new CDbCriteria;


$criteria->condition='id_cv_langue=:id_langue';


$criteria->params=array(':id_language'=>$_POST['cv_text']['id_cv_language']);


$listcat=cv_texte::model()->findAll($criteria);

I am stuck with : How can I get the title of the category?

In your relations() method, you should use 'cv_category' instead of 'id_cv_category' as the relation name.

Given a cv_texte AR instance, you can access the category title via $cv_texte->cv_category->title.

Thank you very much Qiang it works! :)