Yii Framework Forum: Many_Many Relation Problem In Cdbtestcase - Yii Framework Forum

Jump to content

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

Many_Many Relation Problem In Cdbtestcase Rate Topic: -----

#1 User is offline   berza 

  • Newbie
  • Yii
  • Group: Members
  • Posts: 4
  • Joined: 26-December 10

Posted 01 June 2013 - 06:24 AM

YII version 1.1.13

Hello i have a problem accessing MANY_MANY model relations in my CDbTestCase class method.

Here is the code

tests/fixtures/movies.php
return array(
      'editedMovie'=>array(
	 'title'=>'Lorem ipsum',
	 'description'=>'Lorem ipsum dolor sit amet',
      ), 
);


tests/fixtures/movies_tags.php
return array(
		'tag1'=>array('name'=>'tag1','popularity'=>'5688','active'=>'yes'),
		'tag2'=>array('name'=>'tag2','popularity'=>'1819','active'=>'yes'),
  );


tests/fixtures/movies_movies_tags.php
return array(
		'1'=>array('movieId'=>$this->getRecord('movies', 'editedMovie')->id, 'tagId'=>$this->getRecord('movies_tags', 'tag1')->id),
		'2'=>array('movieId'=>$this->getRecord('movies', 'editedMovie')->id, 'tagId'=>$this->getRecord('movies_tags', 'tag2')->id),
);


models/Movies.php
...
public function relations()
	{
		return array(
			'tags'=>array(self::MANY_MANY, 'MoviesTags', 'movies_movies_tags(movieId, tagId)'),
		);
	}
..


tests/unit/UserTest.php
class UsersTest extends CDbTestCase{
	
	public $fixtures=array(
		'movies_tags'=>'MoviesTags',
		'movies'=>'Movies',
		'movies_movies_tags'=>'MoviesMoviesTags',
	);
       
        ////////////////////////
        // BELOW IS THE PROBLEM
        ////////////////////////

	public function testAction(){
                $editedMovie=$this->movies('editedMovie');
		echo count($editedMovie->tags);         // prints 0 - incorrect output, expected 2
		$editedMovie=Movies::model()->findByPk($editedMovie->id);
		echo count($editedMovie->tags);         // prints 2, correct output
		exit;                
        }
}


as you see in UsersTest::testAction if we load an instance of Movies using CDbTestCase we can not access it's MANY_MANY relation, but right after that we load the needed model using CActiveRecord findByPk method, and this way all the relation exists. What i'm doing wrong or is it a Yii bug?

Thanks
0

#2 User is offline   berza 

  • Newbie
  • Yii
  • Group: Members
  • Posts: 4
  • Joined: 26-December 10

Posted 03 June 2013 - 11:23 AM

no solution? Is it a bug?
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