コード例 #1
0
 protected static function canAggregateInMySql(Repository $repository, $columnName, &$relationshipsToAutoHydrate)
 {
     $schema = $repository->getSchema();
     $columns = $schema->getColumns();
     if (isset($columns[$columnName])) {
         return true;
     }
     if (strpos($columnName, ".") !== false) {
         // If the column name contains a dot, the part before the dot is the name of a relationship to another model
         list($relationship, $columnName) = explode(".", $columnName, 2);
         $relationships = SolutionSchema::getAllRelationshipsForModel($repository->getModelClass());
         // Check for the name being that of a relationship
         if (isset($relationships[$relationship]) && $relationships[$relationship] instanceof OneToMany) {
             $targetModelName = $relationships[$relationship]->getTargetModelName();
             $targetSchema = SolutionSchema::getModelSchema($targetModelName);
             $targetColumns = $targetSchema->getColumns();
             // Check for the column name in the schema of the related model
             if (isset($targetColumns[$columnName])) {
                 $relationshipsToAutoHydrate[] = $relationship;
                 return true;
             }
         }
     }
     return false;
 }
コード例 #2
0
 /**
  * Determines if $columnName could be filtered with the MySql repository.
  *
  * If $columnName contains a dot (.) then we will check to see if we can auto hydrate the navigation
  * property.
  *
  * Note $propertiesToAutoHydrate is passed by reference as this how the filtering stack is able to
  * communication back to the repository which properties require auto hydration (if supported).
  *
  * @param Repository $repository
  * @param $columnName
  * @param $propertiesToAutoHydrate
  * @return bool True if the MySql Repository can add this filter to it's where clause.
  */
 protected static function canFilter(Repository $repository, $columnName, &$propertiesToAutoHydrate)
 {
     $schema = $repository->getSchema();
     $columns = $schema->getColumns();
     if (!isset($columns[$columnName])) {
         if (stripos($columnName, ".") !== false) {
             $parts = explode(".", $columnName);
             if (sizeof($parts) == 2) {
                 $relationship = $parts[0];
                 $relationships = SolutionSchema::getAllRelationshipsForModel($repository->getModelClass());
                 if (isset($relationships[$relationship]) && $relationships[$relationship] instanceof OneToOne) {
                     // This is a foreign field and as the __isset() returned true there must be a relationship for this
                     $propertiesToAutoHydrate[] = $relationship;
                 }
             } else {
                 return false;
             }
         } else {
             return false;
         }
     }
     return true;
 }