private function getColumnSchemaForColumnReference($columnReference, $fromModelSchema)
    {
        if (strpos($columnReference, ".") !== false) {
            $parts = explode(".", $columnReference);

            $relationshipName = $parts[0];

            $this->ensureRelationshipsArePopulated();
            $relationships = &Application::current()->getSharedArray("ModelRelationships");

            if (isset($relationships[$this->modelName][$relationshipName])) {
                $relationship = $relationships[$this->modelName][$relationshipName];
                $relatedModel = SolutionSchema::getModel($relationship->getTargetModelName());

                return $relatedModel->getColumnSchemaForColumnReference($parts[1], $fromModelSchema);
            }
        }

        $schema = $fromModelSchema ? $this->getSchema() : $this->getRepository()->getRepositorySchema();
        $columns = $schema->getColumns();

        if (isset($columns[$columnReference])) {
            return $columns[$columnReference];
        }

        return null;
    }