protected function set_up_display() { $category1 = ''; $category2 = ''; if (isset($this->category_1_id)) { $category1 = Category1::find_by_id((int) $this->category_1_id); $this->category_1 = $category1->category_1; } if (isset($this->category_2_id)) { $category2 = Category2::find_by_id((int) $this->category_2_id); $this->category_2 = $category2->category_2; } if (isset($this->category_1_id) && isset($this->category_1_id)) { if ($category1 && $category2) { $this->category = $this->category_1 . "../.. " . $this->category_2; } } }
public function testLazyRecursiveRelation() { $post = PostExt2::model()->findByPk(2); $this->assertEquals(2, count($post->comments)); $this->assertTrue($post->comments[0]->post instanceof Post2); $this->assertTrue($post->comments[1]->post instanceof Post2); $this->assertTrue($post->comments[0]->author instanceof User2); $this->assertTrue($post->comments[1]->author instanceof User2); $this->assertEquals(3, count($post->comments[0]->author->posts)); $this->assertEquals(3, count($post->comments[1]->author->posts)); $this->assertTrue($post->comments[0]->author->posts[1]->author instanceof User2); // test self join $category = Category2::model()->findByPk(1); $this->assertEquals(2, count($category->nodes)); $this->assertTrue($category->nodes[0]->parent instanceof Category2); $this->assertTrue($category->nodes[1]->parent instanceof Category2); $this->assertEquals(2, count($category->nodes[0]->children)); // row in test.categories with id 5 (has 2 descendants) $this->assertEquals(0, count($category->nodes[1]->children)); // row in test.categories with id 4 (has 0 descendants) }