2012-12-29 31 views
0

我有表:司機,driver_negotiation,base_negotiation和團隊Yii CDbCriteria:如何從AR中的「3rd」表中獲取價值?

在DriverController模式,我想獲得TEAM_ID(它位於base_negotiation)驅動程序與談判。

在驅動程序模式,我有:

'driverNegotiation' => array(self::HAS_ONE, 'DriverNegotiation', 'driver_id') 

而且在DriverNegotiation:

'baseNegotiation' => array(self::BELONGS_TO, 'BaseNegotiation', 'base_negotiation_id') 

在DriverController我建立類似:

$criteria=new CDbCriteria(array(
    'condition' => 'baseNegotiation.team_id=13', 
    'with' => 'driverNegotiation', 
    'together' => true, 

)); 

,但我得到:

Column not found: 1054 Unknown column 'baseNegotiation.team_id' in 'where clause'. 
The SQL statement executed was: SELECT COUNT(DISTINCT `t`.`id`) FROM `driver` `t` 
LEFT OUTER JOIN `driver_negotiation` `driverNegotiation` ON 
(`driverNegotiation`.`driver_id`=`t`.`id`) WHERE (baseNegotiation.team_id=13) 

所以我可以從driver_nagotiation表中得到所有的東西,但是沒有任何東西從一個表中得到。

我需要使用連接來獲得正確的東西還是有更好的方法?

+3

''with'=>'driverNegotiation.baseNegotiation''。 – DCoder

+0

這正是我想要的!謝謝。 – Gessle

回答

2
'with' => 'driverNegotiation.baseNegotiation' 

這樣做的伎倆。