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.

Anyway

I’va got 3 tables

Books

|id|name|

|1|book1|

|2|book2|

Owners

|id|name|

|1|owner1|

|2|owner2|

List

|book_id(FK)|owner_id(FK)|

|1|1|

|1|2|

|2|1|

|2|2|

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

  {		

    $list=List::model()->with('book','owner')->findAll(array('together'=>true));

    $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 ?>

// HTML

<?php endforeach ?>



in your view.

That did the job. Thx a lot.