2013-01-11 74 views
0

我試圖顯示使用CGridView的車輛模型。建立模型的特定關係YII主動記錄

爲了顯示Fld7465RRef參考列的值,以下SQL SELECT需要:

select VUF._Fld7468_S as Loading_Time_To_DLR 
FROM Vehicles as Vehicles 
left join (_InfoReg7464 as VUF     
inner join _Chrc7246 as CFU 
on VUF._Fld7467RRef = CFU._IDRRef     
and CFU._Description ='Vehicle uploading for DLRTime')     
on Vehicles._IDRRef = VUF._Fld7465RRef 

我不能找到一個解決方案,以建立用於該查詢的關係。

回答

2

一種方式做這將是DAO

$mySqlString = " 
    select VUF._Fld7468_S as Loading_Time_To_DLR 
    FROM Vehicles as Vehicles 
    left join (_InfoReg7464 as VUF     
    inner join _Chrc7246 as CFU 
    on VUF._Fld7467RRef = CFU._IDRRef     
    and CFU._Description ='Vehicle uploading for DLRTime')     
    on Vehicles._IDRRef = VUF._Fld7465RRef 
"; 
$command = Yii::app()->db->createCommand($mySqlString); 
$aResult = $command->query()->readAll(); 

當然,你應該綁定您的參數,如果有的話,有這樣的說法:另一種方式

$command->bindParam(":userID", $userID, PDO::PARAM_STR); 

query-builder