I have tables: driver, driver_negotiation, base_negotiation and team
In DriverController model I want to get the team_id (which is located in base_negotiation) that the driver is negotiating with.
In Driver model I have:
'driverNegotiation' => array(self::HAS_ONE, 'DriverNegotiation', 'driver_id')
And in DriverNegotiation:
'baseNegotiation' => array(self::BELONGS_TO, 'BaseNegotiation', 'base_negotiation_id')
In DriverController I am building something like:
$criteria=new CDbCriteria(array(
'condition' => 'baseNegotiation.team_id=13',
'with' => 'driverNegotiation',
'together' => true,
));
But I get:
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)
So I can get everything from the driver_nagotiation table, but nothing from one table further.
Do I need to use join to get the correct stuff or is there a better way?
This did the trick.