Esempio n. 1
0
 /**
  * @param  LinkMany      $link
  * @return Models
  */
 public function delete(LinkMany $link)
 {
     foreach ($link->getRemoved() as $removed) {
         $removed->delete();
     }
     return $link->getRemoved();
 }
Esempio n. 2
0
 /**
  * @param  LinkMany      $link
  */
 public function update(LinkMany $link)
 {
     foreach ($link->getAdded() as $added) {
         $added->{$this->getForeignKey()} = $link->getModel()->{$this->getKey()};
     }
     foreach ($link->getRemoved() as $added) {
         $added->{$this->getForeignKey()} = null;
     }
 }
Esempio n. 3
0
 public function delete(LinkMany $link)
 {
     $through = $link->getModel()->getLink($this->through);
     $removedIds = $link->getRemoved()->getIds();
     $removedItems = $through->get()->filter(function ($item) use($removedIds) {
         return in_array($item->{$this->getForeignKey()}, $removedIds);
     });
     $through->get()->removeAll($removedItems);
     foreach ($removedItems as $item) {
         $item->delete();
     }
     return $removedItems;
 }
Esempio n. 4
0
 /**
  * @covers ::getRemoved
  */
 public function testGetRemoved()
 {
     $models = [new City(), new City()];
     $link = new LinkMany(new Country(), Country::getRepo()->getRel('cities'), $models);
     $link->add(new City())->remove($models[0])->remove($models[1]);
     $removed = $link->getRemoved();
     $this->assertInstanceOf('Harp\\Harp\\Model\\Models', $removed);
     $this->assertSame($models, $removed->toArray());
 }