Skip to content

Commit c871d85

Browse files
committed
Fix introspection on models in other plugins.
Apply patch from 'Kim Biesbjerg'. Fixes issues introspecting models in associations from different plugins. Fixes #2732
1 parent ca2c122 commit c871d85

File tree

1 file changed

+8
-2
lines changed

1 file changed

+8
-2
lines changed

lib/Cake/View/Helper/FormHelper.php

Lines changed: 8 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -143,6 +143,11 @@ protected function _getModel($model) {
143143
'class' => $plugin . $this->request->params['models'][$model]['className'],
144144
'alias' => $model
145145
));
146+
} elseif (ClassRegistry::isKeySet($this->defaultModel)) {
147+
$defaultObject = ClassRegistry::getObject($this->defaultModel);
148+
if (in_array($model, array_keys($defaultObject->getAssociated()), true) && isset($defaultObject->{$model})) {
149+
$object = $defaultObject->{$model};
150+
}
146151
} else {
147152
$object = ClassRegistry::init($model, true);
148153
}
@@ -319,12 +324,13 @@ public function create($model = null, $options = array()) {
319324
$options = $model;
320325
$model = null;
321326
}
327+
322328
if (empty($model) && $model !== false && !empty($this->request->params['models'])) {
323329
$model = key($this->request->params['models']);
324-
$this->defaultModel = $model;
325330
} elseif (empty($model) && empty($this->request->params['models'])) {
326331
$model = false;
327332
}
333+
$this->defaultModel = $model;
328334

329335
$key = null;
330336
if ($model !== false) {
@@ -366,7 +372,7 @@ public function create($model = null, $options = array()) {
366372
$options['action'] = $this->request->here(false);
367373
} elseif (empty($options['url']) || is_array($options['url'])) {
368374
if (empty($options['url']['controller'])) {
369-
if (!empty($model) && $model != $this->defaultModel) {
375+
if (!empty($model)) {
370376
$options['url']['controller'] = Inflector::underscore(Inflector::pluralize($model));
371377
} elseif (!empty($this->request->params['controller'])) {
372378
$options['url']['controller'] = Inflector::underscore($this->request->params['controller']);

0 commit comments

Comments
 (0)