Take the 2-minute tour ×

I am getting an error in my view:

Warning (512): SQL Error: 1054: Unknown column 'Model.id' in 'where clause' [CORE\cake\libs\model\datasources\dbo_source.php, line 525] $sql = "SELECT Model.model_id, Model.pic_location, Model.model_name FROM models AS Model WHERE Model.id = '20' LIMIT 1" $error = "1054: Unknown column 'Model.id' in 'where clause'" $out = null

My model is unfortunately named "Model", due to the legacy database I am working with. I have used debug and determined that it is using primaryKey of 'id' (as also displayed in the SQL above), despite my model code (see below) explicitly setting the primaryKey to 'model_id'.

The database table is models with a primary key of model_id, so I can only assume the system is using an autoModel.

My model code is 'model.php':

    <?php class Model extends AppModel {

var $name = 'Model';
var $primaryKey = 'model_id';

//The Associations below have been created with all possible keys, those that are not needed can be removed
var $hasMany = array(
	'Pic' => array(
		'className' => 'Pic',
		'foreignKey' => 'model_name',
		'dependent' => false,
		'conditions' => '',
		'fields' => '',
		'order' => '',
		'limit' => '',
		'offset' => '',
		'exclusive' => '',
		'finderQuery' => '',
		'counterQuery' => ''

I originally created the by hand, and when I hit this error, I baked it... with identical results (except I didn't include the empty fields in the hasMany relationship).

I have turned application level caching off temporarily, and cleared the cache, but nothing helps. How can I make it use my model code?

share|improve this question
add comment

1 Answer

up vote 4 down vote accepted

I'm afraid you'll have to rename your Model model to something else. Your Model class extends AppModel, which in turn extends the base model class, which is also called Model. You're bound to get into trouble this way.

If you have a legacy database, just set the $useTable attribute to use a table with a name different from your model.

share|improve this answer
I thought this might be the case, but wasn't sure. Have done that and it has fixed it. Thanks. –  user182860 Oct 2 '09 at 10:40
add comment

Your Answer

