PEAR Forum :: PHP Extension and Application Repository

PEAR Forum Forum Index
 FAQFAQ   SearchSearch   MemberlistMemberlist   RegisterRegister   ProfileProfile   Log in to check your private messagesLog in to check your private messages   Log inLog in 
DB_Table_Database cascading delete

 
Post new topic   Reply to topic    PEAR Forum Forum Index -> Database
View previous topic :: View next topic  
Author Message
lizciz



Joined: 19 Mar 2008
Posts: 10

PostPosted: Thu Jun 05, 2008 10:04 pm    Post subject: DB_Table_Database cascading delete Reply with quote

Hi

I'm having trouble with the cascading delete feature of the DB_Table_Database package, the problem being that it doesn't work Razz

I use the auto generated Database.php file. In it I add a reference like so
Code:

$db->addRef('ImageSet', 'ImageSetID', 'Kittens', null, 'cascade', 'restrict');


Upon deleting a row from 'Kittens', nothing happens with 'ImageSet'. I tried switching 'cascade' to 'restrict' and correctly got an error saying I'm not allowed to delete the row. But 'cascade' does nothing.

Any idea of what could be the problem?

Thanks
lizciz
Back to top
View user's profile Send private message
mark



Joined: 07 Jan 2007
Posts: 1013

PostPosted: Sat Jun 07, 2008 2:02 pm    Post subject: Reply with quote

This might be a bug, and I'd like to verify/analyze the behaviour.

Would it be possible to get a SQL dump of the two (?) tables and the generated (or modified) PHP scripts? Or at least the scripts without a dump?

My email address is wiesemann(at)php(dot)net, thanks.
Back to top
View user's profile Send private message
lizciz



Joined: 19 Mar 2008
Posts: 10

PostPosted: Sat Jun 07, 2008 9:04 pm    Post subject: Reply with quote

Sure. I don't really know what you mean with a SQL dump, but I will supply you with the files.
Back to top
View user's profile Send private message
mark



Joined: 07 Jan 2007
Posts: 1013

PostPosted: Sat Jun 07, 2008 9:58 pm    Post subject: Reply with quote

Thanks for your email, I'll try to take a look at the problem soon.

About "SQL dump": please read yourself => http://en.wikipedia.org/wiki/Database_dump

Anyway, the files that you've sent should be enough.
Back to top
View user's profile Send private message
lizciz



Joined: 19 Mar 2008
Posts: 10

PostPosted: Sun Jun 08, 2008 1:41 am    Post subject: Reply with quote

Aha, I knew what it was, just didnt know what it was called Very Happy Thanks for the link though.

Anyway, I doupt a dump would be of any use to you, since I'm still developing the site and each table has got only two or three rows, with an ID connecting them.

I hope you can make sense of it all, and that I'll hear from you soon Wink
Back to top
View user's profile Send private message
lizciz



Joined: 19 Mar 2008
Posts: 10

PostPosted: Tue Jun 10, 2008 12:09 pm    Post subject: Reply with quote

This issue has been solved. Just for the record, here is the solution.

The addRef() function can have it's fourth parameter set to null if it is the same as the seccond (if the IDs are the same). However, if it is set to null DB_Table uses the tables primary key and in my case, this was not the wanted behaviour, as 'ImageSetID' wasn't the primary key of the table 'Kittens'. This resultet in the cascading delete to work only if the two IDs had the same values.

The fix was to specify the fourth parameter properly, as shown below.
Code:

$db->addRef('ImageSet', 'ImageSetID', 'Kittens', 'ImageSetID', 'cascade', 'restrict');
Back to top
View user's profile Send private message
Display posts from previous:   
Post new topic   Reply to topic    PEAR Forum Forum Index -> Database All times are GMT + 2 Hours
Page 1 of 1

 
Jump to:  
You cannot post new topics in this forum
You cannot reply to topics in this forum
You cannot edit your posts in this forum
You cannot delete your posts in this forum
You cannot vote in polls in this forum



PEAR Forum topic RSS feed 
Powered by phpBB © 2001, 2005 phpBB Group

Provided by Ministry of Web developement

'Actiemonitor' online projectmanagement software