Quick Help in changing id to its name from other table

i have two tables


CREATE TABLE IF NOT EXISTS `tbl_category` (

  `id` int(10) NOT NULL AUTO_INCREMENT,

  `name` varchar(255) COLLATE utf8_unicode_ci NOT NULL,

  PRIMARY KEY (`id`)

) ENGINE=InnoDB DEFAULT CHARSET=utf8 COLLATE=utf8_unicode_ci AUTO_INCREMENT=1 ;

and


CREATE TABLE IF NOT EXISTS `tbl_subcategory` (

  `id` int(10) NOT NULL AUTO_INCREMENT,

  `cid` int(11) NOT NULL,

  `name` varchar(255) COLLATE utf8_unicode_ci NOT NULL,

  PRIMARY KEY (`id`),

  KEY `cid` (`cid`)

) ENGINE=InnoDB DEFAULT CHARSET=utf8 COLLATE=utf8_unicode_ci AUTO_INCREMENT=1 ;

everything is working fine, i want to view

Catergory Name instead of Category ID in Subcatergory _view.php file


	<b><?php echo CHtml::encode($data->getAttributeLabel('cid')); ?>:</b>

	<?php echo CHtml::encode($data->cid); ?>

	<br />




	public function relations()

	{

		// NOTE: you may need to adjust the relation name and the related

		// class name for the relations automatically generated below.

		return array(

			'linkdirectories' => array(self::HAS_MANY, 'Linkdirectory', 'scid'),

			'catergory' => array(self::BELONGS_TO, 'Category', 'cid'),

		);

	}

HuH Solved

in _view.php of subcatergory


<?php echo $data->catergory->name; ?>

This resolves ID to Name :)

category is relationship in Subcatergory model

catergory’ => array(self::BELONGS_TO, ‘Category’, ‘cid’),

and

name is column name of category table :)