Spot\Query::with PHP Method

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.
    public function with($relations = null)
    {
        if ($relations === null) {
            return $this->with;
        }
        $this->with = array_unique(array_merge((array) $relations, $this->with));
        return $this;
    }

Usage Example

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;
 }
All Usage Examples Of Spot\Query::with