【发布时间】:2009-10-02 02:17:23
【问题描述】:
我的视图出现错误:
警告 (512):SQL 错误:1054:“where 子句”中的未知列“Model.id”[CORE\cake\libs\model\datasources\dbo_source.php,第 525 行] $sql = "SELECT
Model.model_id,Model.pic_location,Model.model_nameFROMmodelsASModelWHEREModel.@207654330@LI =' " $error = "1054: 'where 子句'中的未知列 'Model.id'" $out = null
不幸的是,由于我正在使用的旧数据库,我的模型被命名为“模型”。尽管我的模型代码(见下文)将primaryKey显式设置为'model_id',但我已经使用调试并确定它使用'id'的primaryKey(也显示在上面的SQL中)。
数据库表是model_id主键的模型,所以我只能假设系统使用的是autoModel。
我的模型代码是'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' => ''
)
);}?>
我最初是手动创建的,当我遇到这个错误时,我烘焙了它......结果相同(除了我没有在 hasMany 关系中包含空字段)。
我暂时关闭了应用程序级缓存,并清除了缓存,但没有任何帮助。如何让它使用我的模型代码?
【问题讨论】: