SQLSTATE[42S22]: relation / condition criteria

Hello.

Im trying to get data from a data from my table (named Log), but I need to set some conditions. When I set these conditions, my query doesnt work. I got this error:

CDbCommand failed to execute the SQL statement: SQLSTATE[42S22]: Column not found:1054 Unknown column 'dateStart' in 'where clause'

My Command Model

	/**


	 * @return array relational rules.


	 */


	public function relations()


	{


		return array(


		'log'=>array(self::BELONGS_TO, 'Log', 'Log_id'),


		'file'=>array(self::BELONGS_TO,'File','File_id')


		);


	}

My Log Model

	/**


	 * @return array relational rules.


	 */


	public function relations()


	{


		return array(


			'commands'=>array(self::HAS_MANY,'Command','Log_id'),


			'user'=>array(self::BELONGS_TO,'User','User_id')


		);


	}

And my admin action at Log Controller

		$date = '';


		$dateFormatter = new CDateFormatter('en');


		if(!empty($_POST['startdate'])) {


			$dateDB = implode('-',array_reverse(explode('/',$_POST['startdate'])));  


			$condicoes[] = " dateStart >= '{$dateDB}'";


		}


		$criteria->condition = implode(" AND ",$condicoes);


		


		$sort=new CSort('Log');


		$sort->applyOrder($criteria);


		


		$logList=Log::model()->with('user','commands')->findAll($criteria);

Thnks

Do you have a dateStart column in your table?

Yes I do. dateStart is Command table column

Check the generated SQL and execute it directly using your DB client.

The query in my Query Log:

SELECT `Log`.`id` AS t0_c0, `Log`.`date` AS t0_c1, `Log`.`type` AS t0_c2, `Log`.`status` AS t0_c3, `Log`.`pid` AS t0_c4, `Log`.`User_id` AS t0_c5, t1.`id` AS t1_c0, t1.`name` AS t1_c1, t1.`login` AS t1_c2, t1.`password` AS t1_c3, t1.`active` AS t1_c4, t1.`deletedDate` AS t1_c5, t1.`Profile_id` AS t1_c6 FROM `Log`  LEFT OUTER JOIN `User` t1 ON `Log`.`User_id`=t1.`id` WHERE  dateStart >= '2009-03-28'


I need it join with Command.

Call it as …->with(…)->together()->…

The together() call here ensures Yii do not split the join query into several passes.

It works! Thanks