public function models(Models $models) { $key = $this->getRepo()->getPrimaryKey(); $ids = $models->pluckProperty($key); $this->whereIn($key, $ids); return $this; }
/** * 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; }
public function executeModels(Models $models) { if ($models->count() == 1) { $this->model($models->getFirst()); } else { $this->models($models); } $this->execute(); }
/** * @covers ::executeModels */ public function testExecuteModels() { $models1 = new Models([new City(), new City()]); $models2 = new Models([new City()]); $update = $this->getMock('Harp\\Harp\\Query\\Update', ['models', 'model', 'execute'], [City::getRepo()]); $update->expects($this->at(0))->method('models')->with($this->identicalTo($models1))->will($this->returnSelf()); $update->expects($this->at(1))->method('execute'); $update->expects($this->at(2))->method('model')->with($this->identicalTo($models2->getFirst()))->will($this->returnSelf()); $update->executeModels($models1); $update->executeModels($models2); }
/** * @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; }
/** * @param Models $models * @param integer $flags * @return \Harp\Harp\Find */ public function findModels(Models $models, $flags = null) { $keys = $models->pluckPropertyUnique($this->getKey()); return $this->findAllWhereIn($this->getForeignKey(), $keys, $flags)->where($this->getForeignClassKey(), $this->getConfig()->getModelClass()); }
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; }
/** * @return boolean */ public function valid() { return $this->current->valid(); }
/** * Group models by repo, call yield for each repo * * @param Closure $yield Call for each repo ($repo, $models) */ public function byRepo(Closure $yield) { $repos = Objects::groupBy($this->models, function (AbstractModel $model) { return $model->getRepo()->getRootRepo(); }); foreach ($repos as $repo) { $models = new Models(); $models->addObjects($repos->getInfo()); $yield($repo, $models); } }
/** * @return int */ public function count() { return $this->models->count(); }
/** * @covers ::current * @covers ::key * @covers ::next * @covers ::rewind * @covers ::valid */ public function testIterator() { $source = [new City(), new City()]; $models = new Models($source); $key = $models->key(); foreach ($models as $i => $model) { $this->assertSame(current($source), $model); next($source); } }
public function hasModels(Models $models) { return !($models->isEmptyProperty($this->key) or $models->isEmptyProperty($this->classKey)); }
/** * If model doesn't exist, return a void model * * @return AbstractModel */ public function getNext() { return parent::getNext() ?: $this->getRepo()->newVoidModel(); }