Yii Framework Forum: CDb Exception - Yii Framework Forum

Jump to content

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

CDb Exception Rate Topic: -----

#1 User is offline   sebi 

  • Junior Member
  • Pip
  • Yii
  • Group: Members
  • Posts: 65
  • Joined: 06-October 08

Posted 12 August 2009 - 04:54 PM

Hiho,

kann mir mal bitte jemand diese Exception erklären?


CDbException
Description

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

C:\Documents and Settings\Administrator\Apache2\htdocs\yii\framework\db\CDbCommand.php(322)

00310:             }
00311: 
00312:             if($this->_connection->enableProfiling)
00313:                 Yii::endProfile('system.db.CDbCommand.query('.$this->getText().')','system.db.CDbCommand.query');
00314: 
00315:             return $result;
00316:         }
00317:         catch(Exception $e)
00318:         {
00319:             if($this->_connection->enableProfiling)
00320:                 Yii::endProfile('system.db.CDbCommand.query('.$this->getText().')','system.db.CDbCommand.query');
00321:             Yii::log('Error in querying SQL: '.$this->getText().$params,CLogger::LEVEL_ERROR,'system.db.CDbCommand');
00322: throw new CDbException(Yii::t('yii','CDbCommand failed to execute the SQL statement: {error}',
00323:                 array('{error}'=>$e->getMessage())));
00324:         }
00325:     }
00326: }

Stack Trace

#0 C:\Documents and Settings\Administrator\Apache2\htdocs\yii\framework\db\CDbCommand.php(241): CDbCommand->queryInternal('fetchAll', 2)
#1 C:\Documents and Settings\Administrator\Apache2\htdocs\yii\framework\db\ar\CActiveFinder.php(566): CDbCommand->queryAll()
#2 C:\Documents and Settings\Administrator\Apache2\htdocs\yii\framework\db\ar\CActiveFinder.php(402): CJoinElement->runQuery(Object(CJoinQuery))
#3 C:\Documents and Settings\Administrator\Apache2\htdocs\yii\framework\db\ar\CActiveFinder.php(84): CJoinElement->find(Object(CDbCriteria))
#4 C:\Documents and Settings\Administrator\Apache2\htdocs\yii\framework\db\ar\CActiveFinder.php(112): CActiveFinder->query(Object(CDbCriteria), true)
#5 C:\Documents and Settings\Administrator\Apache2\htdocs\blog\protected\controllers\PostController.php(136): CActiveFinder->findAll(Object(CDbCriteria))
#6 C:\Documents and Settings\Administrator\Apache2\htdocs\yii\framework\web\actions\CInlineAction.php(32): PostController->actionList()
#7 C:\Documents and Settings\Administrator\Apache2\htdocs\yii\framework\web\CController.php(300): CInlineAction->run()
#8 C:\Documents and Settings\Administrator\Apache2\htdocs\yii\framework\web\filters\CFilterChain.php(129): CController->runAction(Object(CInlineAction))
#9 C:\Documents and Settings\Administrator\Apache2\htdocs\yii\framework\web\filters\CFilter.php(41): CFilterChain->run()
#10 C:\Documents and Settings\Administrator\Apache2\htdocs\yii\framework\web\CController.php(952): CFilter->filter(Object(CFilterChain))
#11 C:\Documents and Settings\Administrator\Apache2\htdocs\yii\framework\web\filters\CInlineFilter.php(59): CController->filterAccessControl(Object(CFilterChain))
#12 C:\Documents and Settings\Administrator\Apache2\htdocs\yii\framework\web\filters\CFilterChain.php(126): CInlineFilter->filter(Object(CFilterChain))
#13 C:\Documents and Settings\Administrator\Apache2\htdocs\yii\framework\web\CController.php(283): CFilterChain->run()
#14 C:\Documents and Settings\Administrator\Apache2\htdocs\yii\framework\web\CController.php(257): CController->runActionWithFilters(Object(CInlineAction), Array)
#15 C:\Documents and Settings\Administrator\Apache2\htdocs\yii\framework\web\CWebApplication.php(332): CController->run('list')
#16 C:\Documents and Settings\Administrator\Apache2\htdocs\yii\framework\web\CWebApplication.php(120): CWebApplication->runController('post/list')
#17 C:\Documents and Settings\Administrator\Apache2\htdocs\yii\framework\base\CApplication.php(134): CWebApplication->processRequest()
#18 C:\Documents and Settings\Administrator\Apache2\htdocs\blog\index.php(11): CApplication->run()
#19 {main}





Sie wird in diesem stück Code geworfen:


public function actionList()
	{
		$criteria = new CDbCriteria;
		$criteria->condition = 'status='.Post::STATUS_PUBLISHED;
		$criteria->order = 'creationDate DESC'; #### HIER WIRD DIE EXCEPTION GEWORFEN, ABER WARUM???
		
		$withOption = array('author');
		if(!empty($_GET['tag']))
		{
			$withOption['tagFilter']['params'][':tag'] = $_GET['tag'];
			$postCount = Post::model()->with($withOption)->count($criteria);
		}
		else
			$postCount = Post::model()->count($criteria);
			
		$pages = new CPagination($postCount);
		$pages->applyLimit($criteria);

		$models = Post::model()->with($withOption)->findAll($criteria);

		$this->render('list',array(
			'models'=>$models,
			'pages'=>$pages,
		));
	}



Verstehe nicht warum creationDate an der stelle nicht eindeutig sein soll? Gut die Spalte hat einen
anderen Namen als im Blogtutorial, aber daran wird das wohl nicht liegen oder?

greetz

sebi
0

#2 User is offline   Mike 

  • Elite Member
  • PipPipPipPipPip
  • Yii
  • Group: Members
  • Posts: 3,016
  • Joined: 06-October 08
  • Location:Upper Palatinate

Posted 13 August 2009 - 02:36 AM

creationDate kommt vermutlich auch in der Tabelle authors vor, die du ja mit with() mitlädst. Probier mal ??.creationDate oder im Zweifel post.creationDate.
0

#3 User is offline   sebi 

  • Junior Member
  • Pip
  • Yii
  • Group: Members
  • Posts: 65
  • Joined: 06-October 08

Posted 13 August 2009 - 08:31 AM

Ah Ok, damit gehts, also die verknüpften tabellen mit beachten, good2know ;)
Danke dir.
0

#4 User is offline   Dave 

  • Standard Member
  • PipPip
  • Yii
  • Group: Members
  • Posts: 187
  • Joined: 09-October 08

Posted 17 August 2009 - 02:57 AM

Du kannst das ??.<spalte> auch direkt in der Definition der Beziehung definieren, dann brauchst du nachher bei den "find" und findAll" Aufrufen nicht mehr darauf zu achten. Hier mal der Auszug aus dem Guide.

http://www.yiiframew...de/database.arr ('Relational Query Options')

class User extends CActiveRecord
{
    public function relations()
    {
        return array(
            'posts'=>array(self::HAS_MANY, 'Post', 'authorID',
                            'order'=>'??.createTime DESC',
                            'with'=>'categories'),
            'profile'=>array(self::HAS_ONE, 'Profile', 'ownerID'),
        );
    }
}

0

#5 User is offline   sebi 

  • Junior Member
  • Pip
  • Yii
  • Group: Members
  • Posts: 65
  • Joined: 06-October 08

Posted 17 August 2009 - 08:47 AM

Oh ja das spart Code und Hirnzellen ;)
Danke :D
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