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; }
/** * @return mixed */ public function getSourceColumnName() { $sourceColumnName = $this->sourceColumnName; if ($sourceColumnName == "") { $sourceSchema = SolutionSchema::getModelSchema($this->sourceModelName); $sourceColumnName = $sourceSchema->uniqueIdentifierColumnName; } return $sourceColumnName; }
protected function populateNewModelWithRelationshipValues(Model $model) { $schema = SolutionSchema::getModelSchema($this->modelName); $model[$schema->uniqueIdentifierColumnName] = $this->resourceIdentifier; // If we have a parent handler - see if it can populate our model with some foreign keys. $parentHandler = $this->getParentHandler(); if ($parentHandler !== null && $parentHandler instanceof ModelCollectionHandler) { $parentHandler->populateNewModelWithRelationshipValues($model); } }
/** * Finds the schema of the specified model and returns the values for the specified enum field * * @param $modelName * @param $enumFieldName * * @return array */ public static function GetEnumValues($modelName, $enumFieldName) { $schema = SolutionSchema::getModelSchema($modelName); $enum = $schema->getColumns()[$enumFieldName]; return $enum->enumValues; }
protected function getResultColumns() { $schema = SolutionSchema::getModelSchema($this->modelClassName); return [$schema->labelColumnName]; }
private function applyTypeDefinitionsToColumns() { if (!isset(self::$columnTypeFormatters[$this->modelClass])) { self::$columnTypeFormatters[$this->modelClass] = []; self::$columnTypeDecorators[$this->modelClass] = []; $schema = SolutionSchema::getModelSchema($this->modelClass); $columns = $schema->getColumns(); foreach ($this->typeFormatters as $type => $formatter) { foreach ($columns as $columnName => $column) { if ($column instanceof $type) { self::$columnTypeFormatters[$this->modelClass][$columnName] = $formatter; } } } foreach ($this->typeDecorators as $type => $decorator) { foreach ($columns as $columnName => $column) { if ($column instanceof $type) { self::$columnTypeDecorators[$this->modelClass][$columnName] = $decorator; } } } } foreach (self::$columnTypeDecorators[$this->modelClass] as $columnName => $decorator) { $this->columnDecorators[$columnName] = $decorator; } foreach (self::$columnTypeFormatters[$this->modelClass] as $columnName => $formatter) { $this->columnFormatters[$columnName] = $formatter; } }
public function testGetModelSchema() { $modelSchema = SolutionSchema::getModelSchema("UnitTestUser"); $user = new User(); $this->assertEquals($user->getSchema(), $modelSchema); }