Re: Deleting a bunch of interrelated objects

"Jurgen" <[email protected]>
Newsgroups gmane.comp.java.cayenne.user
Message-ID <1F03194BCD5C45F29F38F2120B90A788@IV5>
Hi Hugi

So crazy idea number one is to maybe duplicate your model and revise the 
delete rules, then use this DeleteModel to nuke the customer. The downside 
of this is having to maintain two models, maybe not such a good idea ?

Idea number two is to add a delete method to each of the classes that first 
deletes the children. So you have:

Customer ->> Invoice ->> InvoiceLine ->> InvoiceLineSums

Then add deleteLineSums() to InvoiceLine that deletes its InvoiceLineSums 
with something like:  getObjectContext().deleteObjects( getLineSums() );

Do the same in Invoice where deleteLines() is something like:

    for ( InvoiceLine line : getLines() )  line.deleteLineSums();
    getObjectContext().commitChanges();
    getObjectContext().invalidateObjects( this );
    getObjectContext().deleteObjects( getLines() );

Then the same for Customer .... The downside of all this is that it's not 
very efficient in terms of DB calls, but then you won't have to go all 
caveman like and "write out damn joins like our ancestors did" :-)

Cheers
Jurgen
lmpx.com only provides a reader for public news (NNTP) servers. It is not affiliated with the servers or forums shown here and is not responsible for the content of articles, which is written by their respective authors.