Permalink
Browse files

Fix introspection on models in other plugins.

Apply patch from 'Kim Biesbjerg'.  Fixes issues introspecting
models in associations from different plugins.

Fixes #2732
  • Loading branch information...
1 parent ca2c122 commit c871d85f2b410b020aa4da8786c2c97c3d3e7c03 @markstory markstory committed Apr 18, 2012
Showing with 8 additions and 2 deletions.
  1. +8 −2 lib/Cake/View/Helper/FormHelper.php
@@ -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);
}
@@ -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) {
@@ -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']);

0 comments on commit c871d85

Please sign in to comment.