Ejemplo n.º 1
0
 /**
  * {@inheritdoc}
  *
  * @param \Illuminate\Database\ConnectionInterface   $db
  * @param \rsanchez\Deep\Collection\EntryCollection  $collection
  * @param \rsanchez\Deep\Hydrator\HydratorCollection $hydrators
  * @param string                                     $fieldtype
  * @param \rsanchez\Deep\Model\RelationshipEntry     $model
  */
 public function __construct(ConnectionInterface $db, EntryCollection $collection, HydratorCollection $hydrators, $fieldtype, RelationshipEntry $model)
 {
     parent::__construct($db, $collection, $hydrators, $fieldtype);
     $this->model = $model;
     $this->relationshipCollection = $this->model->siblings($collection->modelKeys())->get();
     foreach ($this->relationshipCollection as $entry) {
         if (!isset($this->entries[$entry->sibling_id])) {
             $this->entries[$entry->sibling_id] = array();
         }
         $this->entries[$entry->sibling_id][] = $entry;
     }
     // add these entry IDs to the main collection
     $collection->addEntryIds($this->relationshipCollection->modelKeys());
 }