model realation problem

I'm not sure which part i have done wrong but i keep getting php error about array when i try to run

 $model = new video;

 $video = $model->with('team')->findAll();

my video model

public function relations()


		// NOTE: you may need to adjust the relation name and the related

		// class name for the relations automatically generated below.

		return array(






00573:     {

00574:         // determine the primary key value

00575:         if(is_string($this->_pkAlias))  // single key

00576:         {

00577:             if(isset($row[$this->_pkAlias]))

00578:                 $pk=$row[$this->_pkAlias];

00579:             else    // no matching related objects

00580:                 return null;

00581:         }

00582:         else // is_array, composite key

00583:         {

00584:             $pk=array();

00585: foreach($this->_pkAlias as $name=>$alias)

00586:             {

00587:                 if(isset($row[$alias]))

00588:                     $pk[$name]=$row[$alias];

00589:                 else    // no matching related objects

00590:                     return null;

00591:             }

00592:             $pk=serialize($pk);

00593:         }


00595:         // retrieve or populate the record according to the primary key value

00596:         if(isset($this->records[$pk]))

00597:             $record=$this->records[$pk];

i always get error at line 585 on Invalid argument supplied for foreach() of CActivefind

i only retrive all record and get record information from both tables…

i know it can be done with simplemysql join statement but if it can be done with Yii relation will be easier logic implementation next time

Did you define primary key for your tables?

thks for the quick reply

i think i have found the problem… its not the team having problem but is the table that have self::hasmany relation having this problem…

i have solve the problem…

in order for the relation to work my comment and member table must have a additional PK col…

is it how Yii work or its a common practice for sql table creating?? becoz for comment and member table, i don't really need a PK as they cant be edited or delete individually.

But adding an additional col is not an issue

It is a good practice to always define a PK for a table.

If you are dealing with legacy databases and don't have the freedom to do so, you may override primaryKey() method in your model to specify which column should be the PK.