Re: Deleting a bunch of interrelated objects

Hugi Thordarson <[email protected]>
Newsgroups gmane.comp.java.cayenne.user
Message-ID <[email protected]>
Yeah, I'll probably end up doing something like that. Although the column name isn't always the same (data "owned" by a Customer can go Customer ->> Invoice ->> InvoiceLine ->> InvoiceLineSums ->> etc) plain SQL is probably the way to go here. I'll just write out them damn joins like our ancestors did.

Thanks,
- hugi



> On 29 May 2019, at 15:26, John Huss <[email protected]> wrote:
> 
> If the column name is the same in all the tables it would be pretty easy to
> loop over all your entities and execute the same delete statement (via raw
> SQLExec). Put all the the entities with that column in a Set and loop over
> them, removing one when it succeeds until the set is empty.
> 
> On Wed, May 29, 2019 at 7:35 AM Hugi Thordarson <[email protected]> wrote:
> 
>> Hi all.
>> 
>> I have a pretty large model where every to-many relationship's delete rule
>> is "Deny" (I like being explicit about the data I delete, especially since
>> the DB in question still doesn't have well specified FKs).
>> 
>> Almost every table in this DB is somehow related to a "Customer" table
>> (sometimes through a chain of tables) that "owns" data.
>> I'm now implementing an operation to nuke a Customer (as in "delete
>> everything related to that customer")—but the data  "owned" by the customer
>> is hugely interrelated, even often creating circular relations.
>> 
>> Do I have any nice options, given a set of DataObjects, to just tell
>> Cayenne to nuke that darn data without any consideration for normal delete
>> rules? As in "usually I wouldn't allow this and Ashwood is very angry at
>> you—but since you really, really want it…".
>> 
>> Note that the whole operation results in a consistent database (even if
>> there are temporary in-memory inconsistencies due to the circular
>> relationships) since the interrelated data is all deleted within the
>> operation.
>> 
>> Cheers,
>> - Hugi
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.