2014-08-28 99 views
0

我需要使用CDbCriteria創建一個查詢:查詢到的Yii CDbCriteria

select t_devices.* 
from t_departmens, t_branches, t_cabinets, t_employees, t_devices 
where t_branches.id_organization = 1 
and t_departmens.id_branch = t_branches.id_branch 
and t_cabinets.id_department = t_departmens.id_department 
and t_employees.id_cabinet = t_cabinets.id_cabinet 
and t_devices.id_employee = t_employees.id_employee 
+1

你嘗試過什麼:Yii's active record guide

AR關係將自動使用GII

閱讀中產生?這很簡單,重寫爲'CDbCriteria'。考慮使用關係! – Justinas 2014-08-28 10:10:43

+0

嘗試使用JOIN,他們很好,樂於助人。之後,嘗試創建一些關係,他們也很好,然後使用** CDbCriteria **,它也很好。 – anwerj 2014-08-28 11:49:35

回答

0

試試這個

$criteria = new CDbCriteria; 
$criteria->select('t_devices.*'); 
$criteria->from('t_departmens, t_branches, t_cabinets, t_employees, t_devices'); 
$criteria->condition('t_branches.id_organization = 1 
and t_departmens.id_branch = t_branches.id_branch 
and t_cabinets.id_department = t_departmens.id_department 
and t_employees.id_cabinet = t_cabinets.id_cabinet 
and t_devices.id_employee = t_employees.id_employee 
');