public function populate()
 {
     $_REQUEST['showqueries'] = 0;
     set_time_limit(3600);
     $renderer = DebugView::create();
     $renderer->writeHeader();
     $renderer->writeInfo("Orient Environment Builder: Do not run while logged in as a member", Director::absoluteBaseURL());
     echo "<div class=\"build\">";
     $numTestObjects = 100;
     $content .= "<br /><br />Creating {$numTestObjects} test objects.. <br />";
     for ($i = 0; $i < $numTestObjects; $i++) {
         $rand = rand(1, 10);
         $testObj = new TestObject();
         $testObj->Code = 'orient-test-' . $rand;
         $testObj->Title = 'OrientDB Test ' . $rand;
         $testObj->Sort = 1;
         $testObj->write(false, true, true);
         // $content .= "{$testObj->Title} <br />";
     }
     $content .= "Creating inherited object <br />";
     $child = Family_Child::create();
     $child->update(array('Name' => "Name First", 'Title' => 'Child'));
     $result = $child->write();
     $numPosts = 100;
     $content .= "Creating {$numPosts} posts and authors <br />";
     for ($i = 0; $i < $numPosts; $i++) {
         $rand = rand(1, 9);
         $author = new Person();
         $author->Name = "Person {$rand}";
         $id = $author->write();
         $post = new Post();
         $post->Title = "Post Title {$rand}";
         $post->AuthorID = $id;
         $post->write();
     }
     $numArticles = 100;
     $content .= "Creating {$numArticles} articles and at least as many tags <br />";
     for ($i = 0; $i < $numArticles; $i++) {
         $rand = rand(1, 999);
         $article = new Article();
         $article->Title = "Article {$rand}";
         $id = $article->write();
         $range = array(1, 2);
         foreach ($range as $val) {
             $tag = new Tag();
             $tag->Name = "Tag {$val}";
             $tag->write();
             $article->Tags()->add($tag);
         }
     }
     echo $content;
     echo "</div>";
     $renderer->writeFooter();
 }
 public function manymany()
 {
     //Create a post and relate it to an author
     $i = rand(1, 999);
     $article = new Article();
     $article->Name = "Article {$i}";
     $id = $article->write();
     $range = array(1, 2);
     foreach ($range as $val) {
         $tag = new Tag();
         $tag->Name = "Tag {$val}";
         $tag->write();
         $article->Tags()->add($tag);
     }
     foreach ($article->Tags() as $tag) {
         SS_Log::log(new Exception(print_r($tag->toMap(), true)), SS_Log::NOTICE);
     }
     SS_Log::log(new Exception(print_r($article->Tags()->count(), true)), SS_Log::NOTICE);
     $firstTag = $article->Tags()->first();
     SS_Log::log(new Exception(print_r($tag->toMap(), true)), SS_Log::NOTICE);
     foreach ($tag->Articles() as $article) {
         SS_Log::log(new Exception(print_r($article->toMap(), true)), SS_Log::NOTICE);
     }
     return $this->customise(new ArrayData(array('Title' => 'Orient DB Sandbox Many_Many')))->renderWith(array('SandboxController', 'AppController'));
 }