is trying to select an invalid column

probably verry simple, but i need help :)

Active record "Daytrip" is trying to select an invalid column "rCity.City". Note, the column must exist in the table or be an expression with alias.




$criteria = new CDbCriteria;

$criteria->select = 'Street, Number, ZipCode, rCity.City';

$daytrip = Daytrip::model()->with('rCity')->findByPk($_GET['IdDaytrip'], $criteria);



What is the relation between the tables?

You may have to use together().

Many to many and has many won’t work with a simple with statement (not sure about together) but if it doesn’t work you have to do something like $criteria->join to set the join statement to get what you want.




public function relations() {

        return array(

            'rCity' => array(self::BELONGS_TO, 'City', 'CityId')

        );

    }



without the rCity.City in the select, it’s producing:


SELECT `t`.`Street` AS `t0_c3`, `t`.`Number`

AS `t0_c4`, `t`.`ZipCode` AS `t0_c6`, `t`.`IdDaytrip` AS `t0_c0`,

`rCity`.`IdCity` AS `t1_c0`, `rCity`.`CountryId` AS `t1_c1`,

`rCity`.`Province` AS `t1_c2`, `rCity`.`Municipality` AS `t1_c3`,

`rCity`.`City` AS `t1_c4`, `rCity`.`Deeplink` AS `t1_c5`,

`rCity`.`Latitude` AS `t1_c6`, `rCity`.`Longitude` AS `t1_c7`,

`rCity`.`GoogleMatch` AS `t1_c8` FROM `Daytrips` `t`  LEFT OUTER JOIN

`Cities` `rCity` ON (`t`.`CityId`=`rCity`.`IdCity`) WHERE (`t`.`IdDaytrip`

IS NULL

so it’s joining fine.