Beispiel #1
0
 /**
  * @param  LinkMany       $link
  */
 public function update(LinkMany $link)
 {
     parent::update($link);
     $affected = new Models();
     foreach ($link->getRemoved() as $removed) {
         $affected->addAll($removed->setPathAndUpdateDescendants(''));
     }
     foreach ($link->getAdded() as $added) {
         $affected->addAll($added->setPathAndUpdateDescendants($link->getModel()->getChildrenPath()));
     }
     return $affected;
 }
Beispiel #2
0
 /**
  * Get all of the linked models
  *
  * @return Models
  */
 public function getModels()
 {
     $all = new Models();
     foreach ($this->items as $item) {
         $all->addAll($item->getCurrentAndOriginal());
     }
     return $all;
 }
Beispiel #3
0
 /**
  * @param  Models   $models
  * @return LinkMany $this
  */
 public function addModels(Models $models)
 {
     $this->current->addAll($models);
     return $this;
 }
Beispiel #4
0
 /**
  * @covers ::addAll
  */
 public function testAddAll()
 {
     $models = new Models();
     $model1 = new City();
     $model2 = new City();
     $model3 = new City();
     $models->addAll(new Models());
     $this->assertEmpty($models);
     $models->addAll(new Models([$model1, $model2]));
     $models->addAll(new Models([$model1, $model3]));
     $this->assertCount(3, $models);
     $this->assertSame([$model1, $model2, $model3], Objects::toArray($models->all()));
 }