Cake\ORM\Query::eagerLoader PHP Method

eagerLoader() public method

Sets the instance of the eager loader class to use for loading associations and storing containments. If called with no arguments, it will return the currently configured instance.
public eagerLoader ( Cake\ORM\EagerLoader $instance = null ) : Cake\ORM\EagerLoader | $this
$instance Cake\ORM\EagerLoader The eager loader to use. Pass null to get the current eagerloader.
return Cake\ORM\EagerLoader | $this
    public function eagerLoader(EagerLoader $instance = null)
    {
        if ($instance === null) {
            if ($this->_eagerLoader === null) {
                $this->_eagerLoader = new EagerLoader();
            }
            return $this->_eagerLoader;
        }
        $this->_eagerLoader = $instance;
        return $this;
    }

Usage Example

Example #1
0
 /**
  * Get CakePHP property
  *
  * @param string $dataName Column data name
  *
  * @throws Exception
  * @return array|string
  */
 protected function getProperty($dataName)
 {
     $dataName = explode('.', trim($dataName));
     if (count($dataName) != 2) {
         throw new Exception('You are set invalid date.');
     }
     $tableAlias = $dataName[0];
     $colName = $dataName[1];
     if ($this->query->repository()->alias() == $tableAlias) {
         return $colName;
     } elseif (array_key_exists($tableAlias, $this->query->contain())) {
         return ['propertyPath' => $this->query->eagerLoader()->normalized($this->query->repository())[$tableAlias]['propertyPath'], 'field' => $colName];
     }
 }
All Usage Examples Of Cake\ORM\Query::eagerLoader