src/Aggregator/FirstAggregator.php
private function applyConditionsWithOrder(QueryInterface $query) : QueryInterface
    {
        $table = $this->getConfig()->getTable();

        $aggregateField = $table->aliasField($this->getConfig()->getField());

        $query->select($this->getConfig()->getDisplayField())
            ->order([$aggregateField => 'ASC']);

        return $query;
    }
private function applyConditionsWithOrder(QueryInterface $query) : QueryInterface
    {
        $table = $this->getConfig()->getTable();

        $aggregateField = $table->aliasField($this->getConfig()->getField());

        $query->select($this->getConfig()->getDisplayField())
            ->order([$aggregateField => 'ASC']);

        return $query;
    }
private function applyConditionsWithOrder ( QueryInterface $ query ) : QueryInterface { $ table = $ this -> getConfig ( ) -> getTable ( ) ; $ aggregateField = $ table -> aliasField ( $ this -> getConfig ( ) -> getField ( ) ) ; $ query -> select ( $ this -> getConfig ( ) -> getDisplayField ( ) ) -> order ( [ $ aggregateField => 'ASC' ] ) ; return $ query ; }
If the aggregated field and display field are NOT the same we are
using ordering on the aggregated field to retrieve the latest record.

@param \Cake\Datasource\QueryInterface $query Query instance
@return \Cake\Datasource\QueryInterface
@link https://stackoverflow.com/a/19411219/2562232
If the aggregated field and display field are NOT the same we are using ordering on the aggregated field to retrieve the latest record .