public function testBelongsTo()
 {
     $rawly = Bug::findFirstById(1);
     $rawly->robot;
     $eagerly = Loader::fromModel(Bug::findFirstById(1), 'Robot');
     $this->assertTrue(property_exists($eagerly, 'robot'));
     $this->assertInstanceOf('Robot', $eagerly->robot);
     $this->assertEquals($rawly->robot->readAttribute('id'), $eagerly->robot->readAttribute('id'));
     // Reverse
     $rawly = Robot::findFirstById(2);
     $rawly->bugs = $this->_resultSetToEagerLoadingEquivalent($rawly->bugs);
     $eagerly = Loader::fromModel(Robot::findFirstById(2), 'Bugs');
     $this->assertTrue(property_exists($eagerly, 'bugs'));
     $this->assertContainsOnlyInstancesOf('Bug', $eagerly->bugs);
     $getIds = function ($obj) {
         return $obj->readAttribute('id');
     };
     $this->assertEquals(array_map($getIds, $rawly->bugs), array_map($getIds, $eagerly->bugs));
     $this->assertEmpty(Loader::fromModel(Robot::findFirstById(1), 'Bugs')->bugs);
     // Test from multiple
     $rawly = $this->_resultSetToEagerLoadingEquivalent(Bug::find(['limit' => 10]));
     foreach ($rawly as $bug) {
         $bug->robot;
     }
     $eagerly = Loader::fromResultset(Bug::find(['limit' => 10]), 'Robot');
     $this->assertTrue(is_array($eagerly));
     $this->assertTrue(array_reduce($eagerly, function ($res, $bug) {
         return $res && property_exists($bug, 'robot');
     }, TRUE));
     $getIds = function ($obj) {
         return property_exists($obj, 'robot') && isset($obj->robot) ? $obj->robot->readAttribute('id') : NULL;
     };
     $this->assertEquals(array_map($getIds, $rawly), array_map($getIds, $eagerly));
 }
示例#2
0
 public function downloadBug($bugId)
 {
     if (isset($bugId)) {
         $bug = Bug::find($bugId);
         if (isset($bug)) {
             $bugFiles = BugFile::where('bug_id', '=', $bugId)->get();
             if (isset($bugFiles)) {
                 foreach ($bugFiles as $bugFile) {
                 }
             }
         }
     }
 }
示例#3
0
 /**
  * Show the form for editing the specified bug.
  *
  * @param  int  $id
  * @return Response
  */
 public function edit($id)
 {
     $bug = Bug::find($id);
     return View::make('bugs.edit', compact('bug'));
 }