Пример #1
0
 /**
  * @return ModelCollection
  */
 public function get()
 {
     return $this->collection->findAll(function ($item) {
         /** @var TableModel $item */
         $modelValue = $this->fromKey == $this->model->pk() ? $this->model->id() : $this->model->get($this->fromKey);
         $relatedValue = $this->foreignKey == $item->pk() ? $item->id() : $item->get($this->foreignKey);
         return $modelValue == $relatedValue;
     });
 }
Пример #2
0
 /**
  * @return ModelCollection $collection
  * @param Stmt $stmt
  */
 public function createCollection(Stmt $stmt)
 {
     $collection = new ModelCollection();
     $collection->setType($this->getClassName());
     $pagination = $this->getPagination();
     while ($model = $stmt->loadIntoObject($this->getClassName())) {
         $model->setCollection($collection);
         $collection->add($model);
         !$pagination ?: $model->setPagination($pagination);
     }
     return $collection;
 }