Reputation: 12431
i would think that a delete would be pretty simple, I haven't been able to figure out why I'm getting these errors and the delete isn't working. I've tried hard coding the id of the record and just running that one line of code. Why would I get these errors, and how would i go about finding how to fix it.
$this->RentalLineitem->delete(1979);
I'm getting the following errors with the simple delete:
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
I figured it out, as soon as I clicked the post button. Odd that I worked on it for an hour couldn't figure out what was going on, but I post the question and I imediately realize that I have 2 records in my RentalLineitem model pointing to Inventory. but I don't know how to delete the question.
Upvotes: 1
Views: 824
Reputation: 50029
Can you post your model associations here? I think there is a problem in the way you've hooked up your models because you can clearly see that the query seems to be joining to the same table (inv AS Inventory ) using the same alias (the reason is is failing)
Upvotes: 2