protected static function calculateByRepository(Repository $repository, Aggregate $originalAggregate, &$relationshipsToAutoHydrate)
 {
     $columnName = str_replace('.', '`.`', $originalAggregate->aggregatedColumnName);
     if (self::canAggregateInMySql($repository, $originalAggregate->aggregatedColumnName, $relationshipsToAutoHydrate)) {
         $aliasName = $originalAggregate->getAlias();
         $originalAggregate->aggregatedByRepository = true;
         return "MAX( `{$columnName}` ) AS `{$aliasName}`";
     }
     return "";
 }
 public function addAggregateColumn(Aggregate $aggregate)
 {
     $columnName = $aggregate->getAggregateColumnName();
     if (strpos($columnName, ".") === false) {
         throw new AggregateNotSupportedException("Sorry, addAggregateColumn requires that the aggregate operate on a one-to-many relationship property");
     }
     $parts = explode(".", $columnName);
     $relationship = $parts[0];
     // Aggregate Columns must be added on properties that are one to many relationships as we need
     // to put group bys into the query.
     $relationships = SolutionSchema::getAllRelationshipsForModel($this->getModelClassName());
     if (!isset($relationships[$relationship])) {
         throw new AggregateNotSupportedException("Sorry, addAggregateColumn requires that the aggregate operate on a one-to-many relationship property");
     }
     if (!$relationships[$relationship] instanceof OneToMany) {
         throw new AggregateNotSupportedException("Sorry, addAggregateColumn requires that the aggregate operate on a one-to-many relationship property");
     }
     $this->aggregates[] = $aggregate;
     return $this;
 }