relation type STAT producess error

i have 2 relations


		return array(

			

			'commentCount'=>array(self::STAT, 'Comment', 'postId'),

			'comments'=>array(self::HAS_MANY, 'Comment', 'postId', 

				'limit'=>'10'

			),

			);




and when i’m getting comments everything is cool,

but when trying with commentCount it produces following error

yii version /1.0.9

PHP Error

Description

Undefined variable: parent

Source File

C:\wamp\framework\db\ar\CActiveFinder.php(1297)




01285:     private function queryOneMany()

01286:     {

01287:         $relation=$this->relation;

01288:         $model=CActiveRecord::model($relation->className);

01289:         $builder=$model->getCommandBuilder();

01290:         $schema=$builder->getSchema();

01291:         $table=$model->getTableSchema();

01292:         $pkTable=$this->_parent->model->getTableSchema();

01293: 

01294:         $fks=preg_split('/[\s,]+/',$relation->foreignKey,-1,PREG_SPLIT_NO_EMPTY);

01295:         if(count($fks)!==count($pkTable->primaryKey))

01296:             throw new CDbException(Yii::t('yii','The relation "{relation}" in active record class "{class}" is specified with an invalid foreign key. The columns in the key must match the primary keys of the table "{table}".',

01297: array('{class}'=>get_class($parent->model), '{relation}'=>$relation->name, '{table}'=>$pkTable->name)));

01298: 

01299:         // set up mapping between fk and pk columns

01300:         $map=array();  // pk=>fk

01301:         foreach($fks as $i=>$fk)

01302:         {

01303:             if(!isset($table->columns[$fk]))

01304:                 throw new CDbException(Yii::t('yii','The relation "{relation}" in active record class "{class}" is specified with an invalid foreign key "{key}". There is no such column in the table "{table}".',

01305:                     array('{class}'=>get_class($parent->model), '{relation}'=>$relation->name, '{key}'=>$fk, '{table}'=>$table->name)));

01306: 

01307:             if(isset($table->foreignKeys[$fk]))

01308:             {

01309:                 list($tableName,$pk)=$table->foreignKeys[$fk];




i think $parent should point to $this->_parent

so you saying that it is yii bug?

nop i didnt say that. i didnt even look at the original file. i just saw the code part in your message

there is original file :)

i did some playing and tried what you said and i received an exception than.

The relation "commentCount" in active record class "PostModel" is specified with an invalid foreign key. The columns in the key must match the primary keys of the table "post".

but i don’t i don’t have any clue why its not working checked pk and fk more thant 100 times

To me it seems like it complains about a difference in key segment count, pk vs. fk. Strange, since you say one of the relationships work. Did you show us the exact relations() spec you use? Syntax seems ok, at least it’s the same as the example in api doc.

/Tommy

Thanks for help. I figured it out there was two things:

  1. Yii bug $parent should point to $this->_parent

cause if something wrong with key you provided you didnt receive exception but receive an error (Undefined variable: parent) witch appear throwing exception.

  1. 2 PK one of them is and foreign key. :D

When i fixed it i received exception and printed compared values then i figured out that my colleague somehow made 2 PK one of them is and foreign key. :D

however it helped to find very small yii bug :)