protected function execute(ICollection $collection, IEntity $parent) { $collectionMapper = $collection->getCollectionMapper(); if (!$collectionMapper instanceof CollectionMapper) { throw new LogicException(); } $builder = $collectionMapper->getSqlBuilder(); $preloadIterator = $parent->getPreloadContainer(); $values = $preloadIterator ? $preloadIterator->getPreloadValues($this->metadata->name) : [$parent->getRawValue($this->metadata->name)]; $cacheKey = md5($builder->buildSelectQuery() . json_encode($values)); $data =& $this->cacheEntityContainers[$cacheKey]; if ($data) { return $data; } $data = $this->fetch(clone $builder, stripos($cacheKey, 'JOIN') !== FALSE, $values); return $data; }
protected function executeCounts(ICollection $collection, IEntity $parent) { $collectionMapper = $collection->getCollectionMapper(); if (!$collectionMapper instanceof CollectionMapper) { throw new LogicException(); } $builder = $collectionMapper->getSqlBuilder(); $preloadIterator = $parent->getPreloadContainer(); $values = $preloadIterator ? $preloadIterator->getPreloadValues('id') : [$parent->id]; $cacheKey = $this->calculateCacheKey($builder, $values); $data =& $this->cacheCounts[$cacheKey]; if ($data !== NULL) { return $data; } $data = $this->fetchCounts($builder, $values); return $data; }
public function getIterator(IEntity $parent, ICollection $collection) { $data = $collection->findById($parent->{$this->metadata->name}->getInjectedValue())->fetchAll(); return new EntityIterator($data); }
public function getIterator(IEntity $parent, ICollection $collection) { $key = $parent->getForeignKey($this->metadata->name); return [$key ? $collection->getById($key) : NULL]; }
public function getIterator(IEntity $parent, ICollection $collection) { $data = $collection->findBy(["this->{$this->joinStorageKey}->id" => $parent->id])->fetchAll(); return new EntityIterator($data); }
protected function applyDefaultOrder(ICollection $collection) { if (isset($this->metadata->args->relationship['order'])) { return $collection->orderBy($this->metadata->args->relationship['order'][0], $this->metadata->args->relationship['order'][1]); } else { return $collection; } }