/** * Prepare query from entity, fetch records and fill them with relations. * * @return Collection */ public function executeAll() { $repository = $this->repository; $entity = $this->entity; $prepare = $repository->prepareQuery($entity->getQuery(), $entity->getRecordClass()); if ($execute = $repository->executePrepared($prepare) && ($results = $repository->fetchAllPrepared($prepare))) { $collection = new Collection($results); if ($entity->getQuery()->isCounted()) { $prepareCount = $repository->prepareSQL('SELECT FOUND_ROWS()'); $repository->executePrepared($prepareCount); $collection->setTotal($prepareCount->fetch(PDO::FETCH_COLUMN)); $entity->count(false); } $collection->setEntity($entity)->setSaved(); return $entity->fillCollectionWithRelations($collection); } return new Collection(); }