diff --git a/cake/console/libs/tasks/view.php b/cake/console/libs/tasks/view.php index 22f5e6703..dceef89d4 100644 --- a/cake/console/libs/tasks/view.php +++ b/cake/console/libs/tasks/view.php @@ -231,28 +231,15 @@ class ViewTask extends Shell { $this->err("The file '{$shortPath}' could not be found.\nIn order to bake a view, you'll need to first create the controller."); exit(); } - $controllerObj = & new $controllerClassName(); $controllerObj->constructClasses(); - $modelClass = $controllerObj->modelClass; $modelKey = $controllerObj->modelKey; $modelObj =& ClassRegistry::getObject($modelKey); - $primaryKey = $modelObj->primaryKey; - $displayField = $modelObj->displayField; - $singularVar = Inflector::variable($modelClass); - $pluralVar = Inflector::variable($this->controllerName); - $singularHumanName = Inflector::humanize($modelClass); - $pluralHumanName = Inflector::humanize($this->controllerName); - $fields = array_keys($modelObj->schema()); - $foreignKeys = $modelObj->keyToTable; - $belongsTo = $modelObj->belongsTo; - $hasOne = $modelObj->hasOne; - $hasMany = $modelObj->hasMany; - $hasAndBelongsToMany = $modelObj->hasAndBelongsToMany; - return compact('modelClass', 'primaryKey', 'displayField', 'singularVar', 'pluralVar', - 'singularHumanName', 'pluralHumanName', 'fields', 'foreignKeys', - 'belongsTo', 'hasOne', 'hasMany', 'hasAndBelongsToMany'); + $fields = array_keys($modelObj->schema()); + $associations = $this->__associations($modelObj); + + return compact('fields', 'associations'); } /** * Assembles and writes bakes the view file. @@ -339,5 +326,24 @@ class ViewTask extends Shell { $this->out(""); exit(); } +/** + * Returns associations for controllers models. + * + * @return array $associations + * @access private + */ + function __associations($model) { + $keys = array('belongsTo', 'hasOne', 'hasMany', 'hasAndBelongsToMany'); + + foreach ($keys as $key => $type){ + foreach ($model->{$type} as $assocKey => $assocData) { + $associations[$type][$assocKey]['primaryKey'] = $model->{$assocKey}->primaryKey; + $associations[$type][$assocKey]['displayField'] = $model->{$assocKey}->displayField; + $associations[$type][$assocKey]['foreignKey'] = $assocData['foreignKey']; + $associations[$type][$assocKey]['controller'] = Inflector::pluralize($assocData['className']); + } + } + return $associations; + } } ?> \ No newline at end of file diff --git a/cake/libs/controller/scaffold.php b/cake/libs/controller/scaffold.php index 5fbc65813..ef2090ec5 100644 --- a/cake/libs/controller/scaffold.php +++ b/cake/libs/controller/scaffold.php @@ -169,25 +169,10 @@ class Scaffold extends Object { $this->scaffoldActions = $controller->scaffold; $this->controller->pageTitle = __('Scaffold :: ', true) . Inflector::humanize($this->action) . ' :: ' . $this->scaffoldTitle; - //template variables - $modelClass = $this->controller->modelClass; - $modelKey = $this->controller->modelKey; - $primaryKey = $this->ScaffoldModel->primaryKey; - $displayField = $this->ScaffoldModel->displayField; - $singularVar = Inflector::variable($modelClass); - $pluralVar = Inflector::variable($this->controller->name); - $singularHumanName = Inflector::humanize($modelClass); - $pluralHumanName = Inflector::humanize($this->controller->name); $fields = array_keys($this->ScaffoldModel->schema()); - $foreignKeys = $this->ScaffoldModel->keyToTable; - $belongsTo = $this->ScaffoldModel->belongsTo; - $hasOne = $this->ScaffoldModel->hasOne; - $hasMany = $this->ScaffoldModel->hasMany; - $hasAndBelongsToMany = $this->ScaffoldModel->hasAndBelongsToMany; + $associations = $this->__associations(); - $this->controller->set(compact('modelClass', 'primaryKey', 'displayField', 'singularVar', 'pluralVar', - 'singularHumanName', 'pluralHumanName', 'fields', 'foreignKeys', - 'belongsTo', 'hasOne', 'hasMany', 'hasAndBelongsToMany')); + $this->controller->set(compact('fields', 'associations')); $this->__scaffold($params); } /** @@ -508,5 +493,24 @@ class Scaffold extends Object { } return LIBS . 'view' . DS . 'templates' . DS . 'scaffolds' . DS . $action . '.ctp'; } +/** + * Returns associations for controllers models. + * + * @return array $associations + * @access private + */ + function __associations() { + $keys = array('belongsTo', 'hasOne', 'hasMany', 'hasAndBelongsToMany'); + + foreach ($keys as $key => $type){ + foreach ($this->ScaffoldModel->{$type} as $assocKey => $assocData) { + $associations[$type][$assocKey]['primaryKey'] = $this->ScaffoldModel->{$assocKey}->primaryKey; + $associations[$type][$assocKey]['displayField'] = $this->ScaffoldModel->{$assocKey}->displayField; + $associations[$type][$assocKey]['foreignKey'] = $assocData['foreignKey']; + $associations[$type][$assocKey]['controller'] = Inflector::pluralize($assocData['className']); + } + } + return $associations; + } } ?> \ No newline at end of file diff --git a/cake/libs/model/model.php b/cake/libs/model/model.php index 395f88b3e..222009f65 100644 --- a/cake/libs/model/model.php +++ b/cake/libs/model/model.php @@ -99,11 +99,6 @@ class Model extends Overloadable { * @access protected */ var $_schema = null; -/** - * - * @deprecated see $_schema - */ - var $_tableInfo = null; /** * List of validation rules. Append entries for validation as ('field_name' => '/^perl_compat_regexp$/') * that have to match with preg_match(). Use these rules with Model::validate() @@ -145,20 +140,6 @@ class Model extends Overloadable { * @access public */ var $tableToModel = array(); -/** - * List of Model names by used tables. Used for associations. - * - * @var array - * @access public - */ - var $modelToTable = array(); -/** - * List of Foreign Key names to used tables. Used for associations. - * - * @var array - * @access public - */ - var $keyToTable = array(); /** * Whether or not transactions for this model should be logged * @@ -678,7 +659,6 @@ class Model extends Overloadable { } } $this->tableToModel[$this->{$assoc}->table] = $assoc; - $this->modelToTable[$assoc] = $this->{$assoc}->table; } /** * Build array-based association from string. @@ -724,15 +704,6 @@ class Model extends Overloadable { } $this->{$type}[$assocKey][$key] = $data; } - - if ($key == 'foreignKey' && !isset($this->keyToTable[$this->{$type}[$assocKey][$key]])) { - $this->keyToTable[$this->{$type}[$assocKey][$key]][0] = $this->{$class}->table; - $this->keyToTable[$this->{$type}[$assocKey][$key]][1] = $this->{$class}->alias; - - if ($this->{$class}->alias != $class) { - $this->keyToTable[$this->{$type}[$assocKey][$key]][2] = $class; - } - } } if (isset($this->{$type}[$assocKey]['with']) && !empty($this->{$type}[$assocKey]['with'])) {