Skip to content

Commit

Permalink
Fix introspection on models in other plugins.
Browse files Browse the repository at this point in the history
Apply patch from 'Kim Biesbjerg'.  Fixes issues introspecting
models in associations from different plugins.

Fixes #2732
  • Loading branch information
markstory committed Apr 18, 2012
1 parent ca2c122 commit c871d85
Showing 1 changed file with 8 additions and 2 deletions.
10 changes: 8 additions & 2 deletions lib/Cake/View/Helper/FormHelper.php
Expand Up @@ -143,6 +143,11 @@ protected function _getModel($model) {
'class' => $plugin . $this->request->params['models'][$model]['className'],
'alias' => $model
));
} elseif (ClassRegistry::isKeySet($this->defaultModel)) {
$defaultObject = ClassRegistry::getObject($this->defaultModel);
if (in_array($model, array_keys($defaultObject->getAssociated()), true) && isset($defaultObject->{$model})) {
$object = $defaultObject->{$model};
}
} else {
$object = ClassRegistry::init($model, true);
}
Expand Down Expand Up @@ -319,12 +324,13 @@ public function create($model = null, $options = array()) {
$options = $model;
$model = null;
}

if (empty($model) && $model !== false && !empty($this->request->params['models'])) {
$model = key($this->request->params['models']);
$this->defaultModel = $model;
} elseif (empty($model) && empty($this->request->params['models'])) {
$model = false;
}
$this->defaultModel = $model;

$key = null;
if ($model !== false) {
Expand Down Expand Up @@ -366,7 +372,7 @@ public function create($model = null, $options = array()) {
$options['action'] = $this->request->here(false);
} elseif (empty($options['url']) || is_array($options['url'])) {
if (empty($options['url']['controller'])) {
if (!empty($model) && $model != $this->defaultModel) {
if (!empty($model)) {
$options['url']['controller'] = Inflector::underscore(Inflector::pluralize($model));
} elseif (!empty($this->request->params['controller'])) {
$options['url']['controller'] = Inflector::underscore($this->request->params['controller']);
Expand Down

0 comments on commit c871d85

Please sign in to comment.