帮助cakephp删除错误

时间:2011-03-09 12:41:12

标签: cakephp

我认为删除会非常简单,我无法弄清楚为什么我收到这些错误并且删除无效。我试过硬编码记录的id并只运行那一行代码。为什么我会得到这些错误,我将如何找到解决方法。

  $this->RentalLineitem->delete(1979);

我在简单删除时遇到以下错误:

  Warning (512): SQL Error: 1066: Not unique table/alias: 'Inventory' [CORE\cake\libs\model\datasources\dbo_source.php, line 684]

  Query: SELECT `RentalLineitem`.`ri_num`, `RentalLineitem`.`h_num`, `RentalLineitem`.`i_num` FROM `rental_inv` AS `RentalLineitem` LEFT JOIN `rental_in` AS `Rental` ON (`RentalLineitem`.`ri_num` = `Rental`.`ri_num`) LEFT JOIN `hotel` AS `Hotel` ON (`RentalLineitem`.`h_num` = `Hotel`.`h_num`) LEFT JOIN `inv` AS `Inventory` ON (`RentalLineitem`.`i_num` = `Inventory`.`id`) LEFT JOIN `inv` AS `Inventory` ON (`Inventory`.`i_num` = `RentalLineitem`.`id`) WHERE `RentalLineitem`.`id` = 1979 LIMIT 1

  Query: DELETE `RentalLineitem` FROM `rental_inv` AS `RentalLineitem` LEFT JOIN `inv` AS `Inventory` ON (`RentalLineitem`.`i_num` = `Inventory`.`id`) LEFT JOIN `rental_in` AS `Rental` ON (`RentalLineitem`.`ri_num` = `Rental`.`ri_num`) LEFT JOIN `hotel` AS `Hotel` ON (`RentalLineitem`.`h_num` = `Hotel`.`h_num`) LEFT JOIN `inv` AS `Inventory` ON (`RentalLineitem`.`i_num` = `Inventory`.`id`) WHERE `RentalLineitem`.`id` = 1979

一旦点击了帖子按钮,我就明白了。奇怪的是,我工作了一个小时无法弄清楚发生了什么,但我发布了问题,我立刻意识到我的RentalLineitem模型中有2条记录指向库存。但我不知道如何删除这个问题。

1 个答案:

答案 0 :(得分:2)

你可以在这里发布你的模特协会吗?我认为您连接模型的方式存在问题,因为您可以清楚地看到查询似乎使用相同的别名(原因是失败)连接到同一个表(inv AS Inventory)