Generate a nested list of dependencies by looping and drilling down through all the model associations.

@param Model $model
@param int $depth
@return array
352511
public function getDependencies(Model $model, $depth = 0) {
        $dependencies = array();

        if ($depth >= 5) {
            return $dependencies;
        }

        foreach (array($model->hasOne, $model->hasMany, $model->hasAndBelongsToMany) as $assocGroup) {
            foreach ($assocGroup as $alias => $assoc) {
                // hasOne, hasMany
                if (isset($assoc['dependent']) && $assoc['dependent']) {
                    $class = $assoc['className'];

                // hasAndBelongsToMany
                } else if (isset($assoc['joinTable'])) {
                    $class = $assoc['with'];

                } else {
                    continue;
                }

                $dependencies[] = array(
                    'alias' => $alias,
                    'model' => $class,
                    'dependencies' => $this->getDependencies($this->introspect($class), ($depth + 1))
                );
            }
        }

        return $dependencies;
    }
938315
protected function properties(Model $model)
    {
        // Process property annotations
        $annotations = '';

        foreach ($model->getProperties() as $name => $hint) {
            $annotations .= $this->class->annotation('property', "$hint \$$name");
        }

        if ($model->hasRelations()) {
            // Add separation between model properties and model relations
            $annotations .= "\n * ";
        }

        foreach ($model->getRelations() as $name => $relation) {
            // TODO: Handle collisions, perhaps rename the relation.
            if ($model->hasProperty($name)) {
                continue;
            }
            $annotations .= $this->class->annotation('property', $relation->hint()." \$$name");
        }

        return $annotations;
    }
769457
protected function _getAliases(Model $Model) {
		$aliases = array_merge(array(
			//$Model->name,
			$Model->alias
				), $this->config[$Model->alias]['aliases']
		);

		foreach ($Model->associations() as $associationType) {
			foreach ($Model->$associationType as $associationKey => $association) {
				if ($association['className'] === $Model->name) {
					$aliases[] = $associationKey;
				}
			}
		}

		return $aliases;
	}
169131
private function getForeignKeyForNewAssociation(Model $model)
	{
		$this->setKeys($model);
		$primaryKey = Inflector::instance()->variablize($this->foreignKey[0]);

		return array(
			$primaryKey => $model->id,
		);
	}
1049648
public function getModelLinks(Model $model) {
        $models = Configure::read('Admin.modelLinks');

        if (isset($models[$model->qualifiedName])) {
            return $models[$model->qualifiedName];
        }

        return array();
    }
615914
public function retrieve(Model $model, $source)
    {
        return [
            'from' => parent::retrieve($model, $this->getAttributeFrom()),
            'to'   => parent::retrieve($model, $this->getAttributeTo()),
        ];
    }
509868
public static function buildAttributes($model)
    {
        $result = [];

        self::buildCastedAttributes($model, $result);
        self::buildSearchAttributes($model, $result);

        return $result;
    }
76112
protected function getEagerModelKeys(array $models)
    {
        $keys = array();

        /**
         * First we need to gather all of the keys from the parent models so we know what
         * to query for via the eager loading query. We will add them to an array then
         * execute a "where in" statement to gather up all of those related records.
         */
        foreach ($models as $model)
        {
            // In the case of fetching nested relations, we will get an array
            // with the first key being the model we need, and the other being
            // the related model so we'll just take the first model out of the array.
            if (is_array($model)) $model = reset($model);

            if ( ! is_null($value = $model->{$this->ownerKey}))
            {
                $keys[] = $value;
            }
        }

        /**
         * If there are no keys that were not null we will just return an empty array in
         * it so the query doesn't fail, but will not return any results, which should
         * be what this developer is expecting in a case where this happens to them.
         */
        if (count($keys) == 0)
        {
            return array();
        }

        return array_values(array_unique($keys));
    }
1335297
public static function extractModelAndKeys($model, array $keys = null)
    {
        if (! is_null($keys)) {
            if (is_string($model)) {
                $model = new $model;
            }

            return [$model, $keys];
        }

        if ($model instanceof Model) {
            return [$model, [$model->getKey()]];
        }

        if ($model instanceof Collection) {
            $keys = $model->map(function ($model) {
                return $model->getKey();
            });

            return [$model->first(), $keys];
        }
    }
203622
protected function showDatabaseFields(Model $model)
    {
        $this->title("Table {$model->getTable()} :");

        if ( ! $this->db->isConnected()) {
            $this->warn("Not Connected to databse, please check your connection config\r");
        } else {
            $fields = $this->db->getFields($model->getTable());
            $headers = ['name', 'type', 'null', 'length', 'unsigned', 'autoincrement', 'primary_key', 'foreign_key'];

            $this->table($headers, $fields->toArray());
        }
    }
535304
protected function getTableAndDatabase($model)
    {
        $table = $model->getConnection()->getTablePrefix() . $model->getTable();

        $database = null;

        if (strpos($table, '.')) {
            list($database, $table) = explode('.', $table);
        }

        return [$table, $database];
    }
675486
public function toArrayRaw(Entity $entity, $depth=0) {
		$res = [];

		foreach($entity->getDefinition()->properties() as $name=>$property) {
			if($entity->getDefinition()->property($name) instanceof Property\EntityProperty) {
				if($depth < 1)
					$res[$name] = $entity->get($name, null, false);
				else {
					if($entity->getDefinition()->property($name)->get('many')) {
						foreach($entity->get($name, null, false) as $subentity)
							$res[$name][] = $subentity->toArrayRaw($depth-1);
					}
					else {
						if($subentity = $entity->get($name, null, false))
							$res[$name] = $subentity->toArrayRaw($depth-1);
						else
							$res[$name] = null;
					}
				}
			}
			elseif($entity->getDefinition()->property($name)->get('many'))
				$res[$name] = $entity->get($name)->all();
			else
				$res[$name] = $entity->get($name);
		}

		return $res;
	}
350131
public function referencing(Model $model)
    {
        $references = [];

        // TODO: SchemaManager should do this
        foreach ($this->schemas as $schema) {
            $references = array_merge($references, $schema->referencing($model->getBlueprint()));
        }

        // TODO: ModelManager should do this
        foreach ($references as &$related) {
            $blueprint = $related['blueprint'];
            $related['model'] = $model->getBlueprint()->is($blueprint->schema(), $blueprint->table())
                ? $model
                : $this->makeModel($blueprint->schema(), $blueprint->table(), false);
        }

        return $references;
    }
794261
public function getSubClassMappingsWith(string $dependencyMode): array
    {
        $mappings = [];

        foreach ($this->getSubClassMappings() as $classType => $mapping) {
            if ($mapping->getDependencyMode() === $dependencyMode) {
                $mappings[$classType] = $mapping;
            }
        }

        return $mappings;
    }
692208
public function getLocaleDependencies($locale) {
		$dependencies = array();
		if (isset($this->localeDependencies[$locale])) {
			$dependencies = $this->localeDependencies[$locale];

				// Search for dependencies recursively
			$localeDependencies = $dependencies;
			foreach ($localeDependencies as $dependency) {
				if (isset($this->localeDependencies[$dependency])) {
					$dependencies = array_merge($dependencies, $this->getLocaleDependencies($dependency));
				}
			}
		}
		return $dependencies;
	}
131112
public function getDependencies($params)
    {
        $deps = [];
        foreach ($params as $param) {
            $dependency = $param->getClass();
            if ($dependency !== null) {
                if ($dependency->name == 'Proem\Service\AssetManager' || $dependency->name == 'Proem\Service\AssetManagerInterface') {
                    $deps[] = $this;
                } else {
                    $deps[] = $this->resolve($dependency->name);
                }
            } else {
                if ($param->isDefaultValueAvailable()) {
                    $deps[] = $param->getDefaultValue();
                }
            }
        }
        return $deps;
    }
323819
public function getDeepRelations(Model $model, $extended = true) {
        $contain = array_keys($model->belongsTo);
        $contain = array_merge($contain, array_keys($model->hasAndBelongsToMany));

        if ($extended) {
            foreach (array($model->hasOne, $model->hasMany) as $assocs) {
                foreach ($assocs as $alias => $assoc) {
                    $contain[$alias] = array_keys($model->{$alias}->belongsTo);
                }
            }
        }

        return $contain;
    }