當我刪除一個分類,我得到這個錯誤Cakephp。 SQLSTATE [42S22]:列未找到:在 '字段列表' 1054未知列 'CalendarsClassification.id'
Error: SQLSTATE[42S22]: Column not found: 1054 Unknown column 'CalendarsClassification.id' in 'field list'
SQL Query: SELECT `CalendarsClassification`.`id` FROM `calendars_classifications` AS `CalendarsClassification` WHERE `CalendarsClassification`.`calendar_id` = 221
CalendarsClassification
。 id
不存在,但我不知道如何改變它。
ClassificationsController
public function delete($id = null) {
if (!$id) {
$this->flash(__('Invalid Classification', true), array('controller'=>'clients','action'=>'index'));
}
$this->request->data = $this->Classification->read(null, $id);
if ($this->Classification->delete($id, true)) {
$this->flash(__('Classificació esborrada.', true), array('controller'=>'blocks','action'=>'view',$this->data['Classification']['block_id']));
}
}
機型分類
class Classification extends AppModel {
var $name = 'Classification';
var $validate = array(
'long_name' => array(
'rule' => array('minLength', 1)
)
);
//The Associations below have been created with all possible keys, those that are not needed can be removed
var $belongsTo = array(
'Block' => array('className' => 'Block',
'foreignKey' => 'block_id',
'conditions' => '',
'fields' => '',
'order' => ''
)
);
var $hasMany = array(
'Line' => array('className' => 'Line',
'foreignKey' => 'classification_id',
'conditions' => '',
'fields' => '',
'order' => '',
'limit' => '',
'offset' => '',
'dependent' => true,
'exclusive' => '',
'finderQuery' => '',
'counterQuery' => ''
)
);
var $hasAndBelongsToMany = array(
'Calendar' => array('className' => 'Calendar',
'joinTable' => 'calendars_classifications',
'foreignKey' => 'calendar_id',
'associationForeignKey'=> 'classification_id',
'conditions' => '',
'fields' => '',
'order' => '',
'limit' => '',
'unique' => true,
'finderQuery' => '',
'deleteQuery' => '',
)
);
}
'CalendarsClassification'表中存在'id'字段..? – Yash
試試這個$ this-> Classification-> delete(array('CalendarsClassification.calendar_id'=> $ id),false); – Yash