public function testJoin() { $blogDataSource = Mock_Blog::getDataSource(); $entity = $blogDataSource->makeNew(); $entity->set("Title", "This is the first blog"); $entity->set("Description", "and this is the first description"); $blogDataSource->create($entity); $blogCommentDataSource = Mock_BlogComment::getDataSource(); $entity = $blogCommentDataSource->makeNew(); $entity->set("BlogId", 2); $entity->set("Comment", "WTF"); $blogCommentDataSource->create($entity); $entity = $blogCommentDataSource->makeNew(); $entity->set("BlogId", 1); $entity->set("Comment", "Blog Comment"); $blogCommentDataSource->create($entity); $blog = $entity->getRelation("BlogId"); $filter = $blogCommentDataSource->makeFilter(); $filter->addJoin($blogCommentDataSource->getTableName(), "BlogId", $blogDataSource->getTableName(), "Id"); $filter->addConditional($blogDataSource->getTableName(), "Title", "This is the first blog"); $dataset = $blogCommentDataSource->retrieve($filter); $this->assertType("Atrox_Core_Data_Dataset", $dataset); $this->assertType("Mock_BlogComment", $blogCommentRecord = $dataset->getNext()); $this->assertEquals("Blog Comment", $blogCommentRecord->get("Comment")); }
public function testGetRelation() { $dataSource = Mock_Blog::getDataSource(); $entity = $dataSource->makeNew(); $entity->set("Title", "This is the first blog"); $entity->set("Description", "and this is the first description"); $dataSource->create($entity); $dataSource = Mock_BlogComment::getDataSource(); $entity = $dataSource->makeNew(); $entity->set("BlogId", 1); $entity->set("Comment", "Blog Comment"); $dataSource->create($entity); $blog = $entity->getRelation("BlogId"); $this->assertEquals("This is the first blog", $blog->get("Title")); }