On Dec 1, 2009, at 10:41 AM, Jeff Dunnett wrote:
Anjo,
Well the idea is to select a single primary key and then yes it to quickly delete a large number of records from a table.
Using SQL query like this:
DELETE FROM "cms"."ms_contestant" WHERE contest_id = (SELECT contest_id FROM "cms"."ms_contestant" WHERE contest_event = '2009 Contest');
Rather then WebObjects code like this:
NSArray contestants = contest.contestants();
for(int i = 0; i < contestants.count(); i++){
Contestant contesant = (Contestant)contestants.objectAtIndex(i);
ec.deleteObject(contestant);
}
Well, that seems like the hard way.
How about:
contest.deleteAllContestantRelationships();
That will do basically what you've written above, but it's one line of code and will properly handle both sides of the relationship.
Or, if the contestant() relationship on Contest either Owns Destination or has a Cascade delete rule:
ec.deleteObject(contest);
I'm not sure what the SQL will look like for that though.
Are you running into performance problems, or simply anticipating them?
Dave