コード例 #1
0
 /**
  * CActiveRecord::getRelated doesn't call afterFind() with `through` relation
  * https://github.com/yiisoft/yii/issues/591
  */
 public function testIssue591()
 {
     UserWithWrappers::model()->with('comments')->findByPk(1);
     $this->assertEquals(UserWithWrappers::getCounter('afterFind'), 1);
     $this->assertEquals(PostWithWrappers::getCounter('afterFind'), 0);
     $this->assertEquals(CommentWithWrappers::getCounter('afterFind'), 3);
     $user = UserWithWrappers::model()->findByPk(1);
     $user->comments;
     $this->assertEquals(UserWithWrappers::getCounter('afterFind'), 1);
     $this->assertEquals(PostWithWrappers::getCounter('afterFind'), 0);
     $this->assertEquals(CommentWithWrappers::getCounter('afterFind'), 3);
 }
コード例 #2
0
ファイル: models.php プロジェクト: mjrouser/cityapi
 public static function clearCounters()
 {
     self::$_counters = array();
 }
コード例 #3
0
ファイル: models.php プロジェクト: salem-dev-acc/yiiapp
 public static function setBeforeFindCriteria($criteria)
 {
     self::$_beforeFindCriteria = empty($criteria) ? null : $criteria;
 }
コード例 #4
0
 public function testAfterFindRelational()
 {
     UserWithWrappers::model()->with('posts.comments')->find();
     $this->assertEquals(UserWithWrappers::getCounter('afterFind'), 4);
     $this->assertEquals(PostWithWrappers::getCounter('afterFind'), 5);
     $this->assertEquals(CommentWithWrappers::getCounter('afterFind'), 10);
     UserWithWrappers::model()->with('posts.comments')->findByAttributes(array('username' => 'user2'));
     $this->assertEquals(UserWithWrappers::getCounter('afterFind'), 1);
     $this->assertEquals(PostWithWrappers::getCounter('afterFind'), 3);
     $this->assertEquals(CommentWithWrappers::getCounter('afterFind'), 6);
     UserWithWrappers::model()->with('posts.comments')->findByPk(2);
     $this->assertEquals(UserWithWrappers::getCounter('afterFind'), 1);
     $this->assertEquals(PostWithWrappers::getCounter('afterFind'), 3);
     $this->assertEquals(CommentWithWrappers::getCounter('afterFind'), 6);
     UserWithWrappers::model()->with('posts.comments')->findBySql('SELECT * FROM users WHERE id=2');
     $this->assertEquals(UserWithWrappers::getCounter('afterFind'), 1);
     $this->assertEquals(PostWithWrappers::getCounter('afterFind'), 3);
     $this->assertEquals(CommentWithWrappers::getCounter('afterFind'), 6);
     UserWithWrappers::model()->with('posts.comments')->findAll();
     $this->assertEquals(UserWithWrappers::getCounter('afterFind'), 4);
     $this->assertEquals(PostWithWrappers::getCounter('afterFind'), 5);
     $this->assertEquals(CommentWithWrappers::getCounter('afterFind'), 10);
     UserWithWrappers::model()->with('posts.comments')->findAllByAttributes(array('username' => 'user2'));
     $this->assertEquals(UserWithWrappers::getCounter('afterFind'), 1);
     $this->assertEquals(PostWithWrappers::getCounter('afterFind'), 3);
     $this->assertEquals(CommentWithWrappers::getCounter('afterFind'), 6);
     UserWithWrappers::model()->with('posts.comments')->findAllByPk(2);
     $this->assertEquals(UserWithWrappers::getCounter('afterFind'), 1);
     $this->assertEquals(PostWithWrappers::getCounter('afterFind'), 3);
     $this->assertEquals(CommentWithWrappers::getCounter('afterFind'), 6);
     UserWithWrappers::model()->with('posts.comments')->findAllBySql('SELECT * FROM users');
     $this->assertEquals(UserWithWrappers::getCounter('afterFind'), 4);
     $this->assertEquals(PostWithWrappers::getCounter('afterFind'), 5);
     $this->assertEquals(CommentWithWrappers::getCounter('afterFind'), 10);
 }