Gets all the one to one relationships for a model in an array keyed by the column name in the source model.

@param  $modelClassName
@return OneToOne[]
4892
public static function getAllOneToOneRelationshipsForModelBySourceColumnName($modelClassName)
    {
        $relationships = self::getAllRelationshipsForModel($modelClassName);
        $columnRelationships = [];

        foreach ($relationships as $relationship) {
            if ($relationship instanceof OneToOne) {
                $columnName = $relationship->getSourceColumnName();

                $columnRelationships[$columnName] = $relationship;
            }
        }

        return $columnRelationships;
    }
824624
public static function belongsTo($modelClass, $columnName, $options = []) {
        $options['type'] = self::BELONGS_TO;
        $options['modelClass'] = $modelClass;
        $options['compares'] = [[(false === strpos($columnName, '.')) ? "t.$columnName" : $columnName, "r." . $modelClass::getDb()->getTablePk($modelClass::getTableName()), "="]];
        return new self($options);
    }
437720
private function models() {
		$relationships = $dates = [];
		$tables = config('center.tables');

		//loop through once to create relationships between tables
		foreach ($tables as $table) {

			$dates[$table->name] = [];

			if (!isset($relationships[$table->name])) $relationships[$table->name] = [];
			
			foreach ($table->fields as $field) {
				
				//define relationships
				if ($field->type == 'checkboxes') {
	
					//out from this object
					$order_by = [];
					foreach ($tables[$field->source]->order_by as $column=>$direction) {
						$order_by[] = '->orderBy("' . $column . '", "' . $direction . '")';
					}
					$relationships[$table->name][] = '
					public function ' . $tables[$field->source]->name . '() {
						return $this->belongsToMany("LeftRight\Center\Models\\' . $tables[$field->source]->model . '", "' . $field->name . '", "' . RowController::formatKeyColumn($table->name) . '", "' . RowController::formatKeyColumn($tables[$field->source]->name) . '")' . implode($order_by) . ';
					}
					';
				
					//back from the related object
					$order_by = [];
					foreach ($table->order_by as $column=>$direction) {
						$order_by[] = '->orderBy("' . $column . '", "' . $direction . '")';
					}
					$relationships[$tables[$field->source]->name][] = '
					public function ' . $table->name . '() {
						return $this->belongsToMany("LeftRight\Center\Models\\' . $table->model . '", "' . $field->name . '", "' . RowController::formatKeyColumn($tables[$field->source]->name) . '", "' . RowController::formatKeyColumn($table->name) . '")' . implode($order_by) . ';
					}
					';	

				} elseif (in_array($field->type, ['date', 'datetime'])) {

					$dates[$table->name][] = '\'' . $field->name . '\'';
				
				} elseif ($field->type == 'image') {

					//cannot overwrite property
					$relationships[$table->name][] = '
					public function ' . substr($field->name, 0, -3) . '() {
						return $this->hasOne("LeftRight\Center\Models\File", "id", "' . $field->name . '");
					}
					';
				
				} elseif (in_array($field->type, ['select', 'user'])) {
					
					//public function ' . $tables[$field->source]->name . '() {

					//out from this object
					$relationships[$table->name][] = '
					public function ' . substr($field->name, 0, -3) . '() {
						return $this->belongsTo("LeftRight\Center\Models\\' . $tables[$field->source]->model . '", "' . $field->name . '");
					}
					';
	
					//back from the related object
					$relationships[$tables[$field->source]->name][] = '
					public function ' . $table->name . '() {
						return $this->hasMany("LeftRight\Center\Models\\' . $table->model . '", "' . $field->name . '");
					}
					';
				}
			}
		}
		
		//debug
		//dd($relationships);

		//now we must loop through again; the first loop set relationships on other tables
		foreach ($tables as $table) {
			eval('namespace LeftRight\Center\Models;
			use Illuminate\Database\Eloquent\SoftDeletes;
			use Auth;
			use DateTime;
			use DB;
			use Eloquent;

			class ' . $table->model . ' extends Eloquent {
			    ' . (isset($table->fields->deleted_at) ? 'use SoftDeletes;' : '') . '
				public $table      = \'' . $table->name . '\'; //public intentionally
				public $timestamps = false; //going to override if present
				protected $guarded = [];
				protected $dates   = [' . implode(',', $dates[$table->name]) . '];

				public static function boot() {
					parent::boot();
			        static::creating(function($object) {' . 
				        (isset($table->fields->precedence) ? '
						$object->precedence = DB::table(\'' . $table->name . '\')->max(\'precedence\') + 1;
						' : '') .
				        (isset($table->fields->created_by) ? '
						$object->created_by = Auth::id();
						' : '') .
				        ($table->timestamps && isset($table->fields->created_at) ? '
						$object->created_at = new DateTime();
						' : '') .
				        (isset($table->fields->updated_by) ? '
						$object->updated_by = Auth::id();
						' : '') .
				        ($table->timestamps && isset($table->fields->updated_at) ? '
						$object->updated_at = new DateTime();
						' : '') . 
					'});
			        static::updating(function($object) {' . 
			        	(isset($table->fields->updated_by) ? '
						$object->updated_by = Auth::id();
						' : '') .
				        ($table->timestamps && isset($table->fields->updated_at) ? '
						$object->updated_at = new DateTime();
						' : '') . 
			        '});
				}

				public function creator() {
					return $this->belongsTo(\'User\', \'created_by\');
				}

				public function updater() {
					return $this->belongsTo(\'User\', \'updated_by\');
				}

				' . implode(' ', $relationships[$table->name]) . '
			}');
			
		}

	}
1174976
protected function getClassMappingConfiguration($className)
    {
        if (array_key_exists($className, $this->mappings)) {
            return [
                'className' => $className,
                'mapping' => $this->mappings[$className],
            ];
        }

        $reflection = new \ReflectionClass($className);
        while ($reflection = $reflection->getParentClass()) {
            if (array_key_exists($reflection->getName(), $this->mappings)) {
                return [
                    'className' => $reflection->getName(),
                    'mapping' => $this->mappings[$reflection->getName()],
                ];
            }
        }

        throw new MissingClassMappingConfigurationException($className, array_keys($this->mappings));
    }
1276996
public function getFields($objectName)
    {
        $fieldConfigurations = array();
        $modelConfiguration = $this->getModelConfiguration($objectName);
        if (is_array($modelConfiguration)) {
            $fieldConfigurations = $modelConfiguration['fields'];
        }

        return $fieldConfigurations;
    }
1264192
public function getRelations()
    {
        $relations = $columns = [];

        foreach ($this->builder->fields() as $field) {
            $columns[] = $field->column();
        }

        foreach (array_flatten($columns) as $column) {
            if (str_contains($column, '.')) {
                list($relation) = explode('.', $column);

                if (method_exists($this->model, $relation) &&
                    $this->model->$relation() instanceof Relation
                ) {
                    $relations[] = $relation;
                }
            } elseif (method_exists($this->model, $column) &&
                !method_exists(Model::class, $column)
            ) {
                $relations[] = $column;
            }
        }

        return array_unique($relations);
    }
151800
private static function getTable(string $className): array
    {
        $entities   = EntityCollector::getCollector();
        $fields     = $entities[$className]['field'];
        $idProperty = $entities[$className]['table']['id'];
        $tableName  = $entities[$className]['table']['name'];
        $idColumn   = $fields[$idProperty]['column'];

        return [$tableName, $idProperty, $idColumn, $fields];
    }
805595
protected function getApiMapping($className)
    {
        $apiMapping = Config::inst()->get($className, 'api_field_mapping');
        if ($apiMapping && is_array($apiMapping)) {
            return $apiMapping;
        }
        return [];
    }
408064
protected function replaceClassName($modelName)
    {
        $this->stub = str_replace('{{class_name}}', $modelName, $this->stub);
        $this->stub = str_replace('{{class_name_lw}}', strtolower($modelName), $this->stub);

        return $this;
    }
275961
public function getAll($className)
    {
        $collections = array();
        foreach ($this->cursorClassName as $key => $cursor) {
            if ($cursor === $className) {
                $collections[] = $this->collections[$key];
            }
        }

        return $collections;
    }
1180480
public function getFieldsByClass($className)
    {
        $result = [];

        foreach ($this->fields as $field) {
            if ($field instanceof $className ||
                get_class($field) == $className ||
                (new \ReflectionClass($field))->getShortName() == $className
            ) {
                $result[] = $field;
            }
        }

        return $result;
    }
359676
public function getModelArray(Model $model)
    {
        $result = [];
        foreach ($model->getAttributes() as $key => $value) {
            $result[] = ['type' => 'text', 'name' => $key, 'key' => $key.' :', 'value' => $value];
        }
        unset($result[0]);

        return $result;
    }
888394
public function getSort($className='CSort')
	{
		if(($sort=parent::getSort($className))!==false)
			$sort->modelClass=$this->modelClass;
		return $sort;
	}
477096
protected static function _controllerMethods($className)
    {
        if (!class_exists($className)) {
            return [];
        }

        $methods = (array)get_this_class_methods($className);
        $actions = [];
        foreach ($methods as $methodName) {
            try {
                $method = new ReflectionMethod($className, $methodName);
                if ($method->isPublic()) {
                    $actions[] = $methodName;
                }
            } catch (\ReflectionException $e) {
                // error
            }
        }

        return $actions;
    }
1343834
private function convertRelations($className, array $model, ClassMetadataInfo $metadata)
    {
        if (empty($model['relations'])) {
            return;
        }

        foreach ($model['relations'] as $name => $relation) {
            if ( ! isset($relation['alias'])) {
                $relation['alias'] = $name;
            }
            if ( ! isset($relation['class'])) {
                $relation['class'] = $name;
            }
            if ( ! isset($relation['local'])) {
                $relation['local'] = Inflector::tableize($relation['class']);
            }
            if ( ! isset($relation['foreign'])) {
                $relation['foreign'] = 'id';
            }
            if ( ! isset($relation['foreignAlias'])) {
                $relation['foreignAlias'] = $className;
            }

            if (isset($relation['refClass'])) {
                $type = 'many';
                $foreignType = 'many';
                $joinColumns = array();
            } else {
                $type = isset($relation['type']) ? $relation['type'] : 'one';
                $foreignType = isset($relation['foreignType']) ? $relation['foreignType'] : 'many';
                $joinColumns = array(
                    array(
                        'name' => $relation['local'],
                        'referencedColumnName' => $relation['foreign'],
                        'onDelete' => isset($relation['onDelete']) ? $relation['onDelete'] : null,
                    )
                );
            }

            if ($type == 'one' && $foreignType == 'one') {
                $method = 'mapOneToOne';
            } elseif ($type == 'many' && $foreignType == 'many') {
                $method = 'mapManyToMany';
            } else {
                $method = 'mapOneToMany';
            }

            $associationMapping = array();
            $associationMapping['fieldName'] = $relation['alias'];
            $associationMapping['targetEntity'] = $relation['class'];
            $associationMapping['mappedBy'] = $relation['foreignAlias'];
            $associationMapping['joinColumns'] = $joinColumns;

            $metadata->$method($associationMapping);
        }
    }
901187
public function getClassAnnotations($className, $annotationClassName = null)
    {
        $className = $this->prepareClassReflectionForUsage($className);

        $annotationClassName = $annotationClassName === null ? null : $this->cleanClassName($annotationClassName);
        if (!isset($this->classReflectionData[$className][self::DATA_CLASS_ANNOTATIONS])) {
            return [];
        }
        if ($annotationClassName === null) {
            return $this->classReflectionData[$className][self::DATA_CLASS_ANNOTATIONS];
        }

        $annotations = [];
        foreach ($this->classReflectionData[$className][self::DATA_CLASS_ANNOTATIONS] as $annotation) {
            if ($annotation instanceof $annotationClassName) {
                $annotations[] = $annotation;
            }
        }

        return $annotations;
    }
1254310
protected function decideRelationColumns($relationName)
    {
        // https://stackoverflow.com/a/25472778/3113599
        $relationType = (new \ReflectionClass($this->modelObject->$relationName()))->getShortName();
        $selectColumns = [];

        switch ($relationType) {
            case 'BelongsTo':
                // Laravel 5.8 renamed getForeignKey() to getForeignKeyName()
                $methodName = method_exists($this->modelObject->$relationName(), 'getForeignKeyName') ?
                    'getForeignKeyName' :
                    'getForeignKey'
                ;

                $selectColumns[] = $this->modelObject->$relationName()->{$methodName}();
                break;
            case 'MorphTo':
                $selectColumns[] = $this->modelObject->$relationName()->getForeignKey();
                $selectColumns[] = $this->modelObject->$relationName()->getMorphType();
                break;
        }

        return $selectColumns;
    }