コード例 #1
0
ファイル: RepoModels.php プロジェクト: harp-orm/harp
 /**
  * @param  AbstractModel           $model
  * @return Models                  $this
  * @throws InvalidArgumentExtepion If $model not part of the repo
  */
 public function add(AbstractModel $model)
 {
     if (!$this->repo->isModel($model)) {
         throw new InvalidArgumentException(sprintf('Model must be part of repo %s', $this->repo->getName()));
     }
     return parent::add($model);
 }
コード例 #2
0
ファイル: HasManyThrough.php プロジェクト: harp-orm/harp
 public function insert(LinkMany $link)
 {
     $inserted = new Models();
     if (count($link->getAdded()) > 0) {
         $through = $link->getModel()->getLink($this->through);
         $repo = $this->getThroughRepo();
         foreach ($link->getAdded() as $added) {
             $inserted->add($repo->newModel([$this->getKey() => $link->getModel()->getId(), $this->getForeignKey() => $added->getId()]));
         }
         $through->get()->addAll($inserted);
     }
     return $inserted;
 }
コード例 #3
0
ファイル: LinkMany.php プロジェクト: harp-orm/harp
 /**
  * @param  AbstractModel $model
  * @return LinkMany      $this
  */
 public function add(AbstractModel $model)
 {
     $this->current->add($model);
     $this->updateInverse($model);
     return $this;
 }
コード例 #4
0
ファイル: Save.php プロジェクト: harp-orm/harp
 /**
  * Add only one model without traversing the linked models
  *
  * @param  AbstractModel $model
  * @return Save          $this
  */
 public function addShallow(AbstractModel $model)
 {
     $this->models->add($model);
     return $this;
 }
コード例 #5
0
ファイル: ModelsTest.php プロジェクト: harp-orm/harp
 /**
  * @covers ::has
  */
 public function testHas()
 {
     $model = new City();
     $models = new Models();
     $this->assertFalse($models->has($model));
     $models->add($model);
     $this->assertTrue($models->has($model));
 }