예제 #1
0
 function it_can_create_multiple_entities_at_once(IsPersistable $model)
 {
     $stub = new AlbumStub();
     $model->getAttributes(Argument::any())->willReturn([]);
     $model->build('Album', Argument::type('array'))->shouldBeCalledTimes(3)->willReturn($stub);
     $model->save($stub)->shouldBeCalledTimes(3);
     $collection = $this->setTimes(3)->create('Album');
     $collection[0]->shouldEqual($stub);
     $collection[1]->shouldEqual($stub);
     $collection[2]->shouldEqual($stub);
 }
예제 #2
0
 /**
  * Prepare and assign any applicable relationships.
  *
  * @param  mixed $entity
  * @param  array $attributes
  * @return mixed
  */
 protected function assignRelationships($entity, $attributes)
 {
     $modelAttributes = $this->model->getAttributes($entity);
     // We'll filter through all of the columns, and check
     // to see if there are any defined relationships. If there
     // are, then we'll need to create those records as well.
     foreach ($modelAttributes as $columnName => $value) {
         if ($relationship = $this->findRelation($value)) {
             $entity[$columnName] = $this->fetchRelationId($relationship, $columnName, $attributes);
         }
     }
     return $entity;
 }