關係數據我已經創建了一個控制器,用於檢索JSON格式的數據,我需要JSON格式的所有關係數據如何查詢警予
我的數據庫就像
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();
我應該怎麼查詢關係數據cata_table1領域的產值從表1和cata_table2從表2 讓我結果查詢輸出具有'_id,名稱,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()
{
}
u能使用關係發表您的模型TABLE_3我們可以做到這一點 – Ninad
GII沒有產生關係? – Ninad