CakePHP hasAndBelongsToMany(HABTM)_deleteLinks错误

时间:2014-05-21 22:24:57

标签: cakephp cakephp-2.0

我有两个模型ProductDocumenthasAndBelongsToMany关系相关联。

从产品网站看起来像:

class Product extends AppModel {

     public $hasAndBelongsToMany = array(
         'Document' => array(
             'className' => 'DocumentManager.Document',
             'joinTable' => 'documents_products',
             'foreignKey' => 'product_id',
             'associationForeignKey' => 'document_id',
             'unique' => false,
          )
     )
}

..现在当我在$this->Product->delete();中调用ProductsController时,我收到了sql错误:

Error: SQLSTATE[42S22]: Column not found: 1054 Unknown column 'DocumentsProduct.id' in 'field list'
SQL Query: SELECT `DocumentsProduct`.`id` FROM `kd`.`documents_products` AS `DocumentsProduct` WHERE `DocumentsProduct`.`product_id` = 3

当蛋糕试图找到这两个模型之间的所有关系时,上面的查询是由蛋糕2.4.6 Model.php类创建的。 查找查询如下所示:

$records = $Model->find('all', array(
    'conditions' => array($Model->escapeField($data['foreignKey']) => $id),
    'fields' => $Model->primaryKey,
    'recursive' => -1,
    'callbacks' => false
));

在这种情况下,$Model->primaryKey应该返回product_id,我不知道为什么会返回id

有什么想法吗?

提前谢谢!!

0 个答案:

没有答案
相关问题