Recursive delete

hello

i have a table clientwe and table cidade

cidade have many cliente and clientw have one cidade

when i try delete cidade:

Fatal error: Uncaught exception ‘epExceptionDbAdodb’ with message 'Cannot execute query: mysql error: [1452: Cannot add or update a child row: a foreign key constraint fails (alianza/cliente, CONSTRAINT cliente_ibfk_1 FOREIGN KEY (cidade_id) REFERENCES cidade (id) ON DELETE CASCADE ON UPDATE CASCADE)] in EXECUTE(“Update cliente SET cidade_id = Null WHERE id = 3 OR id = 4 OR id = 5 OR id = 6 OR id = 7 OR id = 8 OR id = 9 OR id = 10 OR id = 11 OR id = 12 OR id = 13 OR id = 14 OR id = 15 OR id = 16 OR id = 17 OR id = 18 OR id = 19 OR id = 20 OR id = 21 OR id = 22 OR id = 23 OR id = 24 OR id = 25 OR id = 26 OR id = 27 OR id = 28 OR id = 29 OR id = 30 OR id = 31 OR id = 32 OR id = 33 OR id = 34 OR id = 35 OR id = 36 OR id = 37 OR id = 38 OR id = 39 OR id = 40 OR id = 41 OR id = 42 OR id = 43 OR id = 44 OR id = 45 OR id = 46 OR id = 47 OR id = 48 OR id = 49 OR id = 50 OR id = 51 OR id = 52”) ’ in D:\workPHP\alianza\lib\phporm\src\db\epDbAdodb.php:188 Stack trace: #0 D:\workPHP\alianza\lib\phporm\src\db\epDb.php(352): in D:\workPHP\alianza\lib\phporm\src\db\epDbAdodb.php on line 188

tanks

Hello Hussan,

According to your description, your problem most likely caused by the FK for both cidade and cliente are not nullable. You should have either one side set to nullable in order to make it work. Besides, you should loop through and delete the cliente before delete cidade (See below). If you have any further inquiries, please do not hesitate to contact me again.

foreach($cidade->getClientes() as $lClientes) {
$lClientes->delete();
}
$cidade->delete();

Best regards,
Rain

hmmm
sorry for my english.

but if i set nullable cidade_id in client, then i will have many client without cidade_id… if i make that is correct ?

and if i make the:


foreach($cidade->getClientes() as $lClientes) {
$lClientes->delete();
}
$cidade->delete(); 

is not manually this technique ? because in object Cliente i need create same code to delete the child of cliente…

why in $cidade->delete(); not have a CASCADE delete?

tanks for your answer and again sorry for my english!

Hello Hussan,

This is a bug in current build which fail to handle composition in PHP ORM. We will fix it up and send you the patch.

Best regards,
Rain

tanks rain!

Hello Hussan,

We have deployed a new build which fixed the composition association cascade delete problem. Please find the patch at the following link.

http://files2.visual-paradigm.com/200807/Patch/20080623p/VP_Suite_Windows_3_3_20080623p.exe

Please make sure your association is in composition type in order to have the cascade effect. If you require any further information, please do not hesitate to contact me.

Best regards,
Rain

hi,

the patch allow to delete recursively?

tanks

Yes, this patch solved the cascade delete problem.

Best regards,
Rain