I’m new to yii… I have problem related to CRUD operation…
in my case, I have two tables as follows,
table 1 - hospital
CREATE TABLE my_database.hospital (
hospitalId INT NOT NULL ,
hospital_name VARCHAR(145) NOT NULL ,
address TEXT NOT NULL ,
city VARCHAR(45) NOT NULL ,
PRIMARY KEY (hospitalId) );
table 2 - patient
CREATE TABLE my_database.patient (
patientId INT NOT NULL AUTO_INCREMENT ,
name VARCHAR(100) NOT NULL ,
nic VARCHAR(12) NULL ,
hospitalId INT(15),
PRIMARY KEY (patientId) );
So I have create CRUD operation for patient table.Both tables connected with hospitalId. I want to display hospital_name in view file instead of hospitalId. Now it automatically displayed hospitalId . How it could be possible? can any one help me? Thank you…
You need to setup a relation to that table, and you can use the relation to reference that field like this:
$data->member->name;
In your transaction model you would place something like:
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(
'member' => array(self::BELONGS_TO, 'Member', 'member_id'),// foreign key
);
}