Crosswalk Table with No Primary Key


I have a “crosswalk” table like so:

CREATE table `usergroup` (
  `userId` int NOT NULL DEFAULT '',
  `groupId` int NOT NULL DEFAULT '',
  KEY `userId` (`userId`, `groupId`)

So it has no need for a primary key.  However, when I want to access the table in Yii, like so:


I get the following error:

Invalid argument supplied for foreach()

on this line:

foreach($this->_table->primaryKey as $name)


Add a primary key to your AR (model class) like so:

public function primaryKey() {
return array(‘userId’, ‘groupId’);


More info can be found on this forum post:

Tagged with:

Leave a Reply

Your email address will not be published. Required fields are marked *