New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Cascade on delete #1932
Comments
Dexie does not have any explicit foreign keys nor automatic cascade deletion. But it has ACID consistency so you can easily create a service method or function function deleteAuthor(authorId) {
return db.transaction('rw', db.books, db.authors, () => {
db.books.where({authorId: authorId}).delete();
db.authors.delete(authorId);
});
} |
Ok thanks. So I guess it is not planned? My main issue with this solution is that I need to keep track of all such objects linked to a single author… (in my case there might be plenty) but I'm thinking that for my specific application it might make more sense to create a separate database for each "author", and put all objects related to this author in the same database, this way deleting a single database is trivial. Also, sorry to hijack here, but since you mention |
Cascading deletes are only relevant in hierarchial structures. One useful pattern for this that I have been advocating for, is to use a |
I see, that would be great to have. Then we can maybe keep this issue and remove the question label? Btw, I created another issue to discuss about undo here #1933 |
Was also looking for a cascade on delete feature. I stumbled upon multiple solutions:
Maybe I missed a crucial point in the documentation. I was hyped by the May I have some guidance for the example I gave (Boards, Lists and Items in separate tables)? Am I wrong running away from a "mono table"? Starting a new project with Dexie 4.0.1, should the |
Traditional cascading deletes can be implemented using DBCore as follows:
Some type of declaration of the foreign keys' properties and tables need to be declared if this shall be implemented generically. This declaration could for example be an argument to the middleware factory function. The add-on |
I have some items (say
Authors
) and some things that link to these items (sayBooks
), but if I delete a given Author, I'd like to delete all items that refer to this author, not to have broken links in the database (I think this corresponds for instance to cascade deletion in django). Is it possible to do that automatically with Dexie.js (either theoretically or in practice)?The text was updated successfully, but these errors were encountered: