Yii Includes Column That Make Query Fail.

Hey guys,

I have this:


$data = Aircall::model()

		    ->with(array('airCallSources' => array('select' => 'airCallSources.ID, airCallSources.AirCallUniq'),

			'radioID' => array('select' => 'radioID.Alias')))

		    ->noInterconnect()

		    ->forTarget($groupID)

		    ->betweenDates($formData->startDate, $formData->stopDate)

		    ->findAll(array(

			'select' => 't.AirSec',

			'condition' => 't.Uniq = airCallSources.AirCallUniq',

			'group' => 't.AirSec'

		    ));

But the query stalls:




SQLSTATE[42000]: [Microsoft][SQL Server Native Client 11.0][SQL Server]Column 'dbo.Aircall.Uniq' is invalid 

in the select list because it is not contained in either an aggregate function 

or the GROUP BY clause.. The SQL statement executed was:



I don’t want to include this column at all.

I’ve checked the query generated. Everything is FINE, EXCEPT for the SELECT clause that includes unwanted columns.

I don’t understand why it select the ‘Uniq’ column. And I can’t find how to change this behavior.

So please, any pointers…

Thanks!

AR will always include PK column. This is because it needs to identify record. Use query builder and construct needed query from scratch without AR models and it will work fine.