@@ -143,6 +143,11 @@ protected function _getModel($model) {
143
143
'class ' => $ plugin . $ this ->request ->params ['models ' ][$ model ]['className ' ],
144
144
'alias ' => $ model
145
145
));
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
+ }
146
151
} else {
147
152
$ object = ClassRegistry::init ($ model , true );
148
153
}
@@ -319,12 +324,13 @@ public function create($model = null, $options = array()) {
319
324
$ options = $ model ;
320
325
$ model = null ;
321
326
}
327
+
322
328
if (empty ($ model ) && $ model !== false && !empty ($ this ->request ->params ['models ' ])) {
323
329
$ model = key ($ this ->request ->params ['models ' ]);
324
- $ this ->defaultModel = $ model ;
325
330
} elseif (empty ($ model ) && empty ($ this ->request ->params ['models ' ])) {
326
331
$ model = false ;
327
332
}
333
+ $ this ->defaultModel = $ model ;
328
334
329
335
$ key = null ;
330
336
if ($ model !== false ) {
@@ -366,7 +372,7 @@ public function create($model = null, $options = array()) {
366
372
$ options ['action ' ] = $ this ->request ->here (false );
367
373
} elseif (empty ($ options ['url ' ]) || is_array ($ options ['url ' ])) {
368
374
if (empty ($ options ['url ' ]['controller ' ])) {
369
- if (!empty ($ model ) && $ model != $ this -> defaultModel ) {
375
+ if (!empty ($ model )) {
370
376
$ options ['url ' ]['controller ' ] = Inflector::underscore (Inflector::pluralize ($ model ));
371
377
} elseif (!empty ($ this ->request ->params ['controller ' ])) {
372
378
$ options ['url ' ]['controller ' ] = Inflector::underscore ($ this ->request ->params ['controller ' ]);
0 commit comments