/** * Fetch and return all rows of this query's result set as an array of key-value pairs * * The first column is the key, the second column is the value. * * @return array */ public function fetchPairs() { if (!$this->hasOrder()) { $this->order(); } $results = $this->query->fetchPairs(); if (!empty($results) && $this->repository->providesValueConversion($this->target)) { $columns = $this->getColumns(); $aliases = array_keys($columns); $colOne = $aliases[0] !== 0 ? $aliases[0] : $columns[0]; $colTwo = count($aliases) < 2 ? $colOne : ($aliases[1] !== 1 ? $aliases[1] : $columns[1]); if ($this->repository->providesValueConversion($this->target, $colOne) || $this->repository->providesValueConversion($this->target, $colTwo)) { $newResults = array(); foreach ($results as $colOneValue => $colTwoValue) { $colOneValue = $this->repository->retrieveColumn($this->target, $colOne, $colOneValue, $this); $newResults[$colOneValue] = $this->repository->retrieveColumn($this->target, $colTwo, $colTwoValue, $this); } $results = $newResults; } } return $results; }