There's a bad model reference
The different code permutations are not directly related to the problem - or may simply indicate another different problem =).
The line of code that is failing is this:
$this->{$model}->getColumnType($column);
Where $this
is the User model instance. What that probably means is that when it fails, the object is not the class you expect to check simply do:
debug(get_class($this->User));
In your controller, it is most likely AppModel
.
What causes this
A typical cause of that kind of "sometimes it works, sometimes it doesn't" problem is that there are some references to the model using the plugin prefix, and there are some that don't i.e.
<?php
App::uses('MyPluginAppModel', 'MyPlugin.Model');
class Group extends MyPluginAppModel {
public $hasMany = array(
'User' => array(
'className' => 'User'
),
#'User' # Or like this
)
}
Whereas it should be like this:
<?php
App::uses('MyPluginAppModel', 'MyPlugin.Model');
class Group extends MyPluginAppModel {
public $hasMany = array(
'User' => array(
'className' => 'MyPlugin.User'
),
#'MyPlugin.User' # Or like this
)
}
What happens here is it depends upon how the relevant model is first accessed, as to what populates the User
key in the class registry and is returned for all subsequent requests for that model reference.
To fix the problem, ensure that the model is always referenced with the correct plugin prefix (or of course no prefix if it's not a plugin model).