Best way to retrieve data from second table


I have two tables: user table with user_id and username (amongst other fields). The other table is project which contains project_id, manager_id and description.

I able to change the update view, so it gives me a dropdownlist with the user names (and save this with the user_id being the manager_id in the project table).

However on the views/project/view.php I still have the manager id showing up.

What is the best way forward:

Change the view.php to contain something like

<?php $this->widget('zii.widgets.CDetailView', array(







			'label'=>'Manager name',

			'value'=>'The name of the manager to retrieve from user table'




)); ?>

or a change to the protected/controllers/ProjectController.php in function actionView?

If the change to the actionView is best (performance and best in line with MVC) how to implement that?

Thanks in advance,


PS. I didn’t build in a relation between the tables at SQL level.

You can add a relation to Project model, saying something like this:

public function relations() {

  return array(

    'manager'=>array(self::BELONGS_TO, 'User', 'manager_id')



and then put a line like this in your CDetailView:





Thanks Dima,

That was the right direction I needed.

When looking at this issue, I learned a great deal from the 1.1 guide about the database.

Another useful link is topic 11546-cgridview-with-mulitple-model in this forum.

Onward on trying to get the search projects by manager name!