Can not use CSort with relation

Hi,

since scopes with "with()" are working now, I got a problem.

Yii: 1.1.1

PHP: 5.3

I have a model, which is queried with a scope with a relation. When I want to sort it by ‘id’, I get this error:




CDbException

Description


CDbCommand failed to execute the SQL statement: SQLSTATE[23000]: Integrity constraint violation: 1052 Column 'id' in order clause is ambiguous

Source File


/path/to/app/lib/yii/db/CDbCommand.php(375)


00363:             }

00364: 

00365:             if($this->_connection->enableProfiling)

00366:                 Yii::endProfile('system.db.CDbCommand.query('.$this->getText().')','system.db.CDbCommand.query');

00367: 

00368:             return $result;

00369:         }

00370:         catch(Exception $e)

00371:         {

00372:             if($this->_connection->enableProfiling)

00373:                 Yii::endProfile('system.db.CDbCommand.query('.$this->getText().')','system.db.CDbCommand.query');

00374:             Yii::log('Error in querying SQL: '.$this->getText().$par,CLogger::LEVEL_ERROR,'system.db.CDbCommand');

00375: throw new CDbException(Yii::t('yii','CDbCommand failed to execute the SQL statement: {error}',

00376:                 array('{error}'=>$e->getMessage())));

00377:         }

00378:     }

00379: }


Stack Trace


#0 /path/to/app/lib/yii/db/CDbCommand.php(265): CDbCommand->queryInternal('fetchAll', 2, Array)

#1 /path/to/app/lib/yii/db/ar/CActiveFinder.php(739): CDbCommand->queryAll()

#2 /path/to/app/lib/yii/db/ar/CActiveFinder.php(413): CJoinElement->runQuery(Object(CJoinQuery))

#3 /path/to/app/lib/yii/db/ar/CActiveFinder.php(85): CJoinElement->find(Object(CDbCriteria))

#4 /path/to/app/lib/yii/db/ar/CActiveRecord.php(1154): CActiveFinder->query(Object(CDbCriteria), true)

#5 /path/to/app/lib/yii/db/ar/CActiveRecord.php(1220): CActiveRecord->query(Object(CDbCriteria), true)

#6 /path/to/app/modules/pii/controllers/PiiHtmlController.php(238): CActiveRecord->findAll(Object(CDbCriteria))

#7 /path/to/app/lib/yii/web/actions/CInlineAction.php(32): PiiHtmlController->actionAdmin()

#8 /path/to/app/lib/yii/web/CController.php(300): CInlineAction->run()

#9 /path/to/app/lib/yii/web/filters/CFilterChain.php(129): CController->runAction(Object(CInlineAction))

#10 /path/to/app/lib/yii/web/filters/CFilter.php(41): CFilterChain->run()

#11 /path/to/app/lib/yii/web/CController.php(993): CFilter->filter(Object(CFilterChain))

#12 /path/to/app/lib/yii/web/filters/CInlineFilter.php(59): CController->filterAccessControl(Object(CFilterChain))

#13 /path/to/app/lib/yii/web/filters/CFilterChain.php(126): CInlineFilter->filter(Object(CFilterChain))

#14 /path/to/app/lib/yii/web/CController.php(283): CFilterChain->run()

#15 /path/to/app/lib/yii/web/CController.php(257): CController->runActionWithFilters(Object(CInlineAction), Array)

#16 /path/to/app/lib/yii/web/CWebApplication.php(320): CController->run('admin')

#17 /path/to/app/lib/yii/web/CWebApplication.php(120): CWebApplication->runController('pii/piiHtml/adm...')

#18 /path/to/app/lib/yii/base/CApplication.php(135): CWebApplication->processRequest()

#19 /path/to/app/www/index.php(15): CApplication->run()

#20 {main}



I can neither fix this by specifying "t.id" oder "tableName.id".

Any ideas?

Best regards,

schmunk