CDbException

Hi,

I didn`t update framework from 1.0.5 version and I have problem with my site after updated framework to latest version (trunk). I saw that the problem is in relations. When I use relational query options with "??." I get exception:

Quote

SQL: SQLSTATE[42000]: Syntax error or access violation: 1064 You have an error in your SQL syntax; check the manual that corresponds to your MySQL server version for the right syntax to use near '??.source="member")' at line 1

My relations in model Member:



public function relations()


	{


		return array(


			'history'=>array(self::HAS_MANY, 'History', 'sourceId','condition'=>'??.source="member"'),


		


		);


	}


My relations in model History:



public function relations()


	{


		return array(


			'member'=>array(self::BELONGS_TO, 'Member', 'sourceId'),	


			'company'=>array(self::BELONGS_TO, 'Company', 'sourceId'),	


		);


	}


Source File

Quote

E:\www\framework\db\CDbCommand.php(318)

00306:            }

00307:

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

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

00310:

00311:            return $result;

00312:        }

00313:        catch(Exception $e)

00314:        {

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

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

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

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

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

00320:        }

00321:    }

00322: }

Stack trace

Quote

#0 E:\www\framework\db\CDbCommand.php(237): CDbCommand->queryInternal('fetchAll', 2)

#1 E:\www\framework\db\ar\CActiveFinder.php(558): CDbCommand->queryAll()

#2 E:\www\framework\db\ar\CActiveFinder.php(403): CJoinElement->runQuery(Object(CJoinQuery))

#3 E:\www\framework\db\ar\CActiveFinder.php(407): CJoinElement->find()

#4 E:\www\framework\db\ar\CActiveFinder.php(80): CJoinElement->find(Object(CDbCriteria))

#5 E:\www\framework\db\ar\CActiveFinder.php(108): CActiveFinder->query(Object(CDbCriteria), true)

#6 E:\www\projects\sok\protected\controllers\MemberController.php(71): CActiveFinder->findAll(Object(CDbCriteria))

#7 E:\www\projects\sok\protected\controllers\MemberController.php(125): MemberController->listSiteUser()

#8 E:\www\framework\web\actions\CInlineAction.php(32): MemberController->actionList()

#9 E:\www\framework\web\CController.php(300): CInlineAction->run()

#10 E:\www\framework\web\filters\CFilterChain.php(129): CController->runAction(Object(CInlineAction))

#11 E:\www\framework\web\filters\CFilter.php(41): CFilterChain->run()

#12 E:\www\framework\web\CController.php(952): CFilter->filter(Object(CFilterChain))

#13 E:\www\framework\web\filters\CInlineFilter.php(59): CController->filterAccessControl(Object(CFilterChain))

#14 E:\www\framework\web\filters\CFilterChain.php(126): CInlineFilter->filter(Object(CFilterChain))

#15 E:\www\framework\web\CController.php(283): CFilterChain->run()

#16 E:\www\framework\web\CController.php(257): CController->runActionWithFilters(Object(CInlineAction), Array)

#17 E:\www\framework\web\CWebApplication.php(332): CController->run('list')

#18 E:\www\framework\web\CWebApplication.php(120): CWebApplication->runController('member/list')

#19 E:\www\framework\base\CApplication.php(133): CWebApplication->processRequest()

#20 E:\www\projects\sok\index.php(11): CApplication->run()

#21 {main}

Generated SQL



Error in querying SQL: SELECT `member`.`id` AS `t0_c0`, history.`id` AS


`t1_c0`, history.`source` AS `t1_c1`, history.`sourceId` AS `t1_c2`,


history.`tstamp` AS `t1_c3`, history.`task` AS `t1_c4`,


history.`description` AS `t1_c5`, history.`dependent` AS `t1_c6`,


history.`dependentId` AS `t1_c7` FROM `member` LEFT OUTER JOIN `history`


history ON (history.`sourceId`=`member`.`id`) WHERE (`member`.`id` IN (10,


9)) AND (??.source="member")


Can someone help me? Thanx!

In version 1.0.7 at 1212 error does not occur :) but in latest problem occur when I try:



$members=Member::model()->with('history')->findAll($criteria);


Thanks to qianq I solved problem. In trunk version removed ??. prefix. Now there is used relation name as the column prefix.