Error in afterFind method

Hello everyone,

I’m new to Yii and new on this forum. I would first like to thank the creators for the beautiful Yii framework.

I have tried to use the afterFind method to set an attribute with the content of another model like this:

public function afterFind()


      $this->Status = Status::model()->findByPk($this->Status)->Status;


When i load just 1 record from the database it’s not an problem but when i try to load more records i get errors. Is there any way to get this working properly?

Regards Primate.

For such a thing I would use yii’s relations feature. In your model you can set a HAS_ONE relation like this:

public function relations() {

  return array( 		

    'Status' => array(self::HAS_ONE,'Status','status_id') 	



the status_id should be a foreign key. hope this helps.

Thanks Greg,

It works!

I am glad it helped :)