Yii Framework Forum: is trying to select an invalid column - Yii Framework Forum

Jump to content

Page 1 of 1
  • You cannot start a new topic
  • You cannot reply to this topic

is trying to select an invalid column Rate Topic: -----

#1 User is offline   bas_vdl 

  • Standard Member
  • PipPip
  • Yii
  • Group: Members
  • Posts: 215
  • Joined: 01-April 09

Posted 19 April 2010 - 12:59 PM

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);

0

#2 User is offline   lgoss007 

  • Junior Member
  • Pip
  • Yii
  • Group: Members
  • Posts: 88
  • Joined: 01-October 09

Posted 19 April 2010 - 02:59 PM

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.
0

#3 User is offline   bas_vdl 

  • Standard Member
  • PipPip
  • Yii
  • Group: Members
  • Posts: 215
  • Joined: 01-April 09

Posted 19 April 2010 - 03:01 PM

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.
0

Share this topic:


Page 1 of 1
  • You cannot start a new topic
  • You cannot reply to this topic

1 User(s) are reading this topic
0 members, 1 guests, 0 anonymous users