public function testHasMany() { $this->createPostsWithComments(5, 10); $this->assertEqual(BlogPost::count(), 5); $this->assertEqual(BlogComment::count(), 50); // Get last post $post = BlogPost::findFirst(["order" => "created_at desc"]); $this->assertEqual($post->title, 'Post 5'); // Test has many collection $queryCount = TipyDAO::$queryCount; $comments = $post->comments; // We got a new query $this->assertEqual(TipyDAO::$queryCount, $queryCount + 1); $this->assertEqual(sizeof($comments), 10); $this->assertEqual($comments[0]->title, 'Comment 1 to post 5'); // Test cached association $this->assertNotEqual($post->associationsCache["comments"], null); $this->assertEqual($comments, $post->associationsCache["comments"]); // Test no query $queryCount = TipyDAO::$queryCount; $commentsAgain = $post->comments; // no more queries $this->assertEqual(TipyDAO::$queryCount, $queryCount); $this->assertEqual($comments, $commentsAgain); // Test has many collection with conditions $comments = $post->comments(["order" => " created_at desc"]); $this->assertEqual(sizeof($comments), 10); $this->assertEqual($comments[0]->title, 'Comment 10 to post 5'); // Test queries association is not cached $this->assertNotEqual($comments, $post->associationsCache["comments"]); }