[eluser]toadies[/eluser]
[quote author="WanWizard" date="1330523791"]
In this setup, the Order table contains the FK 'customer_id'.
When deleting the customer record, Datamapper will fetch the relation definition from the Customer model, and it will check if 'cascading_delete' is set to TRUE on the relation (which it is by default).
[/quote]
My two tables is customers and equipments has one-to-one relations.
In MySQL I have a FK in the equipment table with customer_id as the FK to id in customers table. On Delete is set to Cascade in equipments.
cascade_delete is set to true.
Quote:If so, it will check if there is a relationship table. If there is, it will delete the records from that table, but will not delete any Order records.
If there is no relationship table, it will check if Customer or Order contains the FK that defines the relation.
I have no relationship table.
Quote:If the FK is in the other table, and the other table is equal to the current objects table (only true in a self-referencing relation) and the FK is in the current table, the FK will be set to NULL, and nothing will happen to the other table.
In all other cases, the related record will be deleted.
After this process, the current record itself will be deleted. If you're using a DB capable of transactions, this entire process is wrapped in a transaction to ensure integrity.
If that doesn't happen, then you have just found a bug.
When I try to delete here is my warning message from my script.
Code:
A Database Error Occurred
Error Number: 1452
Cannot add or update a child row: a foreign key constraint fails (`pools_dev`.`equipments`, CONSTRAINT `PK_Customers` FOREIGN KEY (`customer_id`) REFERENCES `customers` (`id`) ON DELETE CASCADE)
UPDATE `equipments` SET `customer_id` = NULL WHERE `customer_id` = 5
The script I don't think is even trying to delete the equipment relationship. Only try to update it to Null.
Is this a bug or am I doing something wrong?
**Edit: I resolved by setting cascade_delete to FALSE and letting mysql handling the relationship.