views:

770

answers:

5

In cake 1.2 there is a feature that allows the developer to no have to create models, but rather have cake do the detective work at run time and create the model for you. This process happens each time and is neat but in my case very hazardous. I read about this somewhere and now I'm experiencing the bad side of this.

I've created a plugin with all the files and everything appeared to be just great. That is until i tried to use some of the model's associations and functions. Then cake claims that this model i've created doesn't exist. I've narrowed it down to cake using this auto model feature instead of throwing and error! So i have no idea what's wrong!

Does anybody know how to disable this auto model feature? It's a good thought, but I can't seem to find where i've gone wrong with my plugin and an error would be very helpful!

+2  A: 

There's always the possibility to actually create the model file and set var $useTable = false.
If this is not what you're asking for and the model and its associations actually do exist, but Cake seems to be unable to find them, you'll have to triple check the names of all models and their class names in both the actual model definition and in the association definitions.

AFAIK you can't disable the auto modelling.

deceze
+1  A: 

Use

var $useTable = false;

in your model definition.

Mladen Mihajlovic
A: 

It's a hack and it's ugly cus you need to edit core cake files but this is how i do it: \cake\libs\class_registry.php : line 127ish

if (App::import($type, $plugin . $class)) {
 ${$class} =& new $class($options);
} elseif ($type === 'Model') {
    /* Print out whatever debug info we have then exit */
    pr($objects);
 die("unable to find class $type, $plugin$class");
    /* We don't want to base this on the app model */
 ${$class} =& new AppModel($options);
}
SeanDowney
+1  A: 

Delete all cached files (all files under app/tmp, keep the folders)

In most cases where models seem to be acting in unexpected ways, often they dont include changes you've made, it is because that cake is useing an old cached version of the model.

Alexander Morland
A: 

Uh...where do we start. First, as Alexander suggested, clear your app cache.

If you still get the same behaviour, there is probably something wrong with the class and/or file names.

Remember the rules, for controller:

* classname: BlastsController
* filename: blasts_controller.php

for model:

* classname: Blast
* filename: blast.php

Don't foget to handle the irregular inflections properly.

dr Hannibal Lecter