As I understand it, you can use initialization scripts instead of classic fixtures. Yii 's documentation states:
It is also possible that we do not like the default method of dumping the table, i.e. truncating it and pasting it with the device data. If so, we can write an initialization script for a specific binding file. The script should be named after the table suffix with .init.php. For example, the initialization script for the Post Table will be Post.init.php. When the CDbFixtureManager sees this script, it will execute this script instead of using the default path to the reset table.
So, in your case, instead of protected/tests/fixtures/Comment.php , you will have protected/tests/fixtures/Comment.init.php that does this:
// the $this variable refers to the CBdFixtureManager instance $this->truncateTable($tableName); $post = $this->getRecord('Post','post1'); // get dependent fixture // define new fixture $commentAttributes = array( 'text' => 'Comment text...', 'post_id' => $post->id ); $comment = new Comment; $comment->setAttributes($commentAttributes); if(!$comment->save()) throw new CException('Unable to save fixture'); // add new row primary key $pk = Comment::model()->getTableSchema()->primaryKey; if(is_string($pk)) $commentAttributes[$pk] = $comment->$pk; elseif(is_array($pk)) foreach($pk as $key) $commentAttributes[$key] = $comment->$key; $this->_rows['Comment']['comment1'] = $commentAttributes; $this->_records['Comment']['comment1'] = 'Comment';
Although I understand this is a very late answer, this should solve your problem. Since I got googling here, I was hoping I could help someone who needs this information.
source share