diff --git a/cake/libs/controller/controller.php b/cake/libs/controller/controller.php index c27fdfb55..cb9f564a9 100644 --- a/cake/libs/controller/controller.php +++ b/cake/libs/controller/controller.php @@ -564,6 +564,7 @@ class Controller extends Object $model = $this->modelClass; $modelKey = $this->modelKey; $table = $this->{$model}->table; + $association = array_search($table,$this->{$model}->alias); $classRegistry =& ClassRegistry::getInstance(); $objRegistryModel = $classRegistry->getObject($modelKey); @@ -580,12 +581,13 @@ class Controller extends Object $fieldNames[ $tabl['name'] ]['prompt'] = Inflector::humanize($niceName); // this is a foreign key, also set up the other controller $fieldNames[ $tabl['name'] ]['table'] = Inflector::pluralize($niceName); + $association = array_search($fieldNames[ $tabl['name'] ]['table'],$this->{$model}->alias); if($this->{$model}->tableToModel[$fieldNames[ $tabl['name'] ]['table']] == $model) { $alias = 'Child_'; } $fieldNames[ $tabl['name'] ]['prompt'] = Inflector::humanize($alias.$niceName); - $fieldNames[ $tabl['name'] ]['model'] = $alias.$this->{$model}->tableToModel[$fieldNames[ $tabl['name'] ]['table']]; + $fieldNames[ $tabl['name'] ]['model'] = $alias.$association; $fieldNames[ $tabl['name'] ]['modelKey'] = $this->{$model}->tableToModel[$fieldNames[ $tabl['name'] ]['table']]; $fieldNames[ $tabl['name'] ]['controller'] = Inflector::pluralize($this->{$model}->tableToModel[Inflector::pluralize($niceName)]); $fieldNames[ $tabl['name'] ]['foreignKey'] = true; @@ -666,14 +668,15 @@ class Controller extends Object { foreach( $pass as $key=>$value ) { - if( $alias.$key == $fieldNames[ $tabl['name']]['model'] && isset( $value['id'] ) && isset( $value[$otherDisplayField] ) ) + + if( $alias.$key == $this->{$model}->tableToModel[$fieldNames[ $tabl['name'] ]['table']] && isset( $value['id'] ) && isset( $value[$otherDisplayField] ) ) { $fieldNames[ $tabl['name']]['options'][$value['id']] = $value[$otherDisplayField]; } } } } - $fieldNames[ $tabl['name']]['selected'] = $data[$table][$tabl['name']]; + $fieldNames[ $tabl['name']]['selected'] = $data[$association][$tabl['name']]; } } else @@ -728,7 +731,7 @@ class Controller extends Object { foreach( $pass as $key=>$value ) { - if( $alias.$key == $fieldNames[ $tabl['name']]['model'] && isset( $value['id'] ) && isset( $value[$otherDisplayField] ) ) + if( $alias.$key == $this->{$model}->tableToModel[$fieldNames[ $tabl['name'] ]['table']] && isset( $value['id'] ) && isset( $value[$otherDisplayField] ) ) { $fieldNames[ $tabl['name']]['options'][$value['id']] = $value[$otherDisplayField]; } @@ -779,8 +782,8 @@ class Controller extends Object // loop through the many to many relations to make a list box. foreach( $objRegistryModel->_manyToMany as $relation ) { - list($modelName) = $relation; - + //list($modelName) = $relation; + list($manyAssociation, $modelName, $value) = $relation; $modelKeyM = Inflector::underscore($modelName); $modelObject = new $modelName(); @@ -790,7 +793,7 @@ class Controller extends Object $fieldNames[$modelKeyM]['model'] = $modelName; $fieldNames[$modelKeyM]['prompt'] = "Related ".Inflector::humanize(Inflector::pluralize($modelName)); $fieldNames[$modelKeyM]['type'] = "selectMultiple"; - $fieldNames[$modelKeyM]['tagName'] = $modelName.'/'.$modelName; + $fieldNames[$modelKeyM]['tagName'] = $manyAssociation.'/'.$manyAssociation; foreach( $modelObject->findAll() as $pass ) { @@ -802,9 +805,9 @@ class Controller extends Object } } } - if( isset( $data[$modelName] ) ) + if( isset( $data[$manyAssociation] ) ) { - foreach( $data[$modelName] as $key => $row ) + foreach( $data[$manyAssociation] as $key => $row ) { $fieldNames[$modelKeyM]['selected'][$row['id']] = $row['id']; } diff --git a/cake/libs/controller/scaffold.php b/cake/libs/controller/scaffold.php index f0328ea6d..9d83a8534 100644 --- a/cake/libs/controller/scaffold.php +++ b/cake/libs/controller/scaffold.php @@ -409,45 +409,45 @@ class Scaffold extends Object { */ function _cleanUpFields() { - $modelKey = Inflector::underscore($this->modelKey); + foreach( $this->controllerClass->{$this->modelKey}->_tableInfo as $table ) { foreach ($table as $field) { - if('date' == $field['type'] && isset($this->controllerClass->params['data'][$modelKey][$field['name'].'_year'])) + if('date' == $field['type'] && isset($this->controllerClass->params['data'][$this->modelKey][$field['name'].'_year'])) { $newDate = mktime( 0,0,0, - $this->controllerClass->params['data'][$modelKey][$field['name'].'_month'], - $this->controllerClass->params['data'][$modelKey][$field['name'].'_day'], - $this->controllerClass->params['data'][$modelKey][$field['name'].'_year'] ); + $this->controllerClass->params['data'][$this->modelKey][$field['name'].'_month'], + $this->controllerClass->params['data'][$this->modelKey][$field['name'].'_day'], + $this->controllerClass->params['data'][$this->modelKey][$field['name'].'_year'] ); $newDate = date( 'Y-m-d', $newDate ); - $this->controllerClass->params['data'][$modelKey][$field['name']] = $newDate; + $this->controllerClass->params['data'][$this->modelKey][$field['name']] = $newDate; } - else if( 'datetime' == $field['type'] && isset($this->controllerClass->params['data'][$modelKey][$field['name'].'_year'] ) ) + else if( 'datetime' == $field['type'] && isset($this->controllerClass->params['data'][$this->modelKey][$field['name'].'_year'] ) ) { - $hour = $this->controllerClass->params['data'][$modelKey][$field['name'].'_hour']; - if( $hour != 12 && 'pm' == $this->controllerClass->params['data'][$modelKey][$field['name'].'_meridian'] ) + $hour = $this->controllerClass->params['data'][$this->modelKey][$field['name'].'_hour']; + if( $hour != 12 && 'pm' == $this->controllerClass->params['data'][$this->modelKey][$field['name'].'_meridian'] ) { $hour = $hour + 12; } $newDate = mktime( $hour, - $this->controllerClass->params['data'][$modelKey][$field['name'].'_min'],0, - $this->controllerClass->params['data'][$modelKey][$field['name'].'_month'], - $this->controllerClass->params['data'][$modelKey][$field['name'].'_day'], - $this->controllerClass->params['data'][$modelKey][$field['name'].'_year'] ); + $this->controllerClass->params['data'][$this->modelKey][$field['name'].'_min'],0, + $this->controllerClass->params['data'][$this->modelKey][$field['name'].'_month'], + $this->controllerClass->params['data'][$this->modelKey][$field['name'].'_day'], + $this->controllerClass->params['data'][$this->modelKey][$field['name'].'_year'] ); $newDate = date( 'Y-m-d H:i:s', $newDate ); - $this->controllerClass->params['data'][$modelKey][$field['name']] = $newDate; + $this->controllerClass->params['data'][$this->modelKey][$field['name']] = $newDate; } else if( 'tinyint(1)' == $field['type'] ) { - if( isset( $this->controllerClass->params['data'][$modelKey][$field['name']]) && - "on" == $this->controllerClass->params['data'][$modelKey][$field['name']] ) + if( isset( $this->controllerClass->params['data'][$this->modelKey][$field['name']]) && + "on" == $this->controllerClass->params['data'][$this->modelKey][$field['name']] ) { - $this->controllerClass->params['data'][$modelKey][$field['name']] = true; + $this->controllerClass->params['data'][$this->modelKey][$field['name']] = true; } else { - $this->controllerClass->params['data'][$modelKey][$field['name']] = false; + $this->controllerClass->params['data'][$this->modelKey][$field['name']] = false; } } } diff --git a/cake/libs/controller/templates/scaffolds/list.thtml b/cake/libs/controller/templates/scaffolds/list.thtml index 2e1e533ee..467aec324 100644 --- a/cake/libs/controller/templates/scaffolds/list.thtml +++ b/cake/libs/controller/templates/scaffolds/list.thtml @@ -61,17 +61,17 @@ getObject( $otherModelKey ); + $alias = array_search($value['table'],$this->controller->{$model}->alias); if( is_object($otherModelObject) ) { - $displayText = $row[$value['model']][ $otherModelObject->getDisplayField() ]; + $displayText = $row[$alias][ $otherModelObject->getDisplayField() ]; } else{ - $displayText = $row[$value['model']][$field]; + $displayText = $row[$alias][$field]; } echo $html->linkTo( $displayText, "/".Inflector::underscore($otherControllerName)."/show/".$row[$modelKey][$field] ); diff --git a/cake/libs/controller/templates/scaffolds/show.thtml b/cake/libs/controller/templates/scaffolds/show.thtml index 284eda4b6..962225516 100644 --- a/cake/libs/controller/templates/scaffolds/show.thtml +++ b/cake/libs/controller/templates/scaffolds/show.thtml @@ -44,10 +44,10 @@ echo "