name column from different table

I’ve been trying to figure out how to do that and I’m sure the problem is quite easy, not for me thoug.


I’va got 3 tables















Model List relation:

	public function relations()


  return array(

    'owner' => array(self::BELONGS_TO, 'Owners', 'owner_id'),

    'book' => array(self::BELONGS_TO, 'Books', 'book_id'),



ListController indexAction:

class SListController extends Controller


  public $list;


  public function actionIndex()



    $this->list = $list;

    $this->render('index', array('list'=>$this->list));


Now it returns only id columns and names are private properties, so I can’t access them in View.

Can you tell me how to get it to work so that I can read names in View?

P.S Sorry for my English.

Related models are stored in private properties but they can be accessed via magic getters and setters as they would be public. I can’t see anything wrong with your code, just try something like this

<?php foreach ($list as $listItem) : ?>

// HTML here...

  <?php echo $listItem->book->name ?>


<?php endforeach ?>

in your view.

That did the job. Thx a lot.