I have created a controller for retrieving data in JSON format for which I need all relational data in json format
my database is like
TABLE_1
_id category1
1 fruit
2 vegetable
TABLE_2
_id type
1 winter
2 summer
TABLE_3
_id name cata_table1 cata_table2
1 apple 1 2
Here cata_table1 is foreign key to TABLE_1 and cata_table2 foreign key to TABLE_2
$sql="SELECT * from TABLE_3";
$command=$connection->createCommand($sql);
$row=$command->queryAll();
How should I query relational data to output value of cata_table1 field from table1 and cata_table2 from table2 so that my result query output has `_id, name, TABLE_1.category1 , TABLE_2.type
model TABLE_3
class TABLE_3 extends CActiveRecord
{
public static function model($className=__CLASS__)
{
return parent::model($className);
}
public function tableName()
{
return 'TABLE_3';
}
public function rules()
{
return array(
array('_id,name,cata_table1,cata_table2', 'required'),
array('_id, name, cata_table1, cata_table2', 'safe', 'on'=>'search'),
);
}
public function relations()
{
}