Getting Foreign Fields Related To Another Related Foreign Table (Tables And Relationships)

Hi. I have this problem regarding foreign keys.

I have four (4) tables.

  1. Server

  2. Patching (scheduling)

  3. Os

  4. OsVersion

Server → os_id

Server → os_version_id

Patching → server_id

In Patching, I would like to view the (os_id → os_name) and (os_version_id → os_version_name) but I can’t. I can only get the upto the ID of each table.

I did this in my view.php:

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



		array('label'=>'Operating System','value'=>CHtml::encode(ServerInventory::model()->findByPk($model->server_inventory_id)->os_id)),

		array('label'=>'Operating System Version','value'=>CHtml::encode(ServerInventory::model()->findByPk($model->server_inventory_id)->os_version_id)),


)); ?>

And I already did this in Patching’s model:

public function relations()


		return array(






Hope someone could help me. Thanks in advance!

[color="#FFFF00"]//I’m sorry this shouldn’t be under Installation and Setup Category. :([/color]

Please read about relations and lazy loading. After you define your relations you can read them like ordinary attributes. Related records will be loaded when needed.