with() public method

Relations to be eager-loaded
public with ( mixed | null $relations = null )
$relations mixed | null Array/string of relation(s) to be loaded.
Example #1
0
 /**
  * {@inheritDoc}
  */
 public function read(Query $query)
 {
     $builder = $query->builder();
     $queryHash = md5($builder->getSql() . '_' . serialize($builder->getParameters()));
     if ($this->mapper instanceof MapperCacheInterface) {
         if ($builder->getType() == 0) {
             $collection = $this->mapper->getQueryFromCache($queryHash);
             if ($collection) {
                 return $collection;
             }
         } else {
             $this->mapper->clearQueryCache();
         }
     }
     /*
     if ($query->builder()->getType() == 0) {
         $clonedQuery = clone $query->builder();
     
         $res = $clonedQuery->getConnection()->executeQuery('EXPLAIN ' . $clonedQuery->getSQL(), $clonedQuery->getParameters(), $clonedQuery->getParameterTypes());
         $res->setFetchMode(\PDO::FETCH_ASSOC);
     
         echo '<pre>';
         var_dump($queryHash);
         var_dump($clonedQuery->getSQL());
         var_dump($clonedQuery->getParameters());
         var_dump($res->fetchAll());
         echo '</pre>';
     }
     */
     $stmt = $builder->execute();
     $stmt->setFetchMode(\PDO::FETCH_ASSOC);
     $collection = $query->mapper()->collection($stmt, $query->with());
     $stmt->closeCursor();
     if ($this->mapper instanceof MapperCacheInterface && $builder->getType() == 0) {
         $this->mapper->addQueryToCache($queryHash, $collection);
     }
     return $collection;
 }
Example #2
0
 /**
  * Find records with custom SQL query
  *
  * @param \Spot\Query $query SQL query to execute
  * @return \Spot\Entity\Collection
  * @throws \Spot\Exception
  */
 public function read(Query $query)
 {
     $stmt = $query->builder()->execute();
     // Set PDO fetch mode
     $stmt->setFetchMode(\PDO::FETCH_ASSOC);
     $collection = $query->mapper()->collection($stmt, $query->with());
     // Ensure statement is closed
     $stmt->closeCursor();
     return $collection;
 }
Example #3
0
 /**
  * Return result set for current query
  */
 public function toCollection(\Spot\Query $query, $stmt)
 {
     $mapper = $query->mapper();
     $entityClass = $query->entityName();
     if ($stmt instanceof \PDOStatement) {
         // Set PDO fetch mode
         $stmt->setFetchMode(\PDO::FETCH_ASSOC);
         $collection = $mapper->collection($entityClass, $stmt, $query->with());
         // Ensure statement is closed
         $stmt->closeCursor();
         return $collection;
     } else {
         $mapper->addError(__METHOD__ . " - Unable to execute query " . implode(' | ', $this->connection()->errorInfo()));
         return array();
     }
 }