Add ActiveHasMany Mutation (ability to delete) - #3195
Closed
Jacob-32587 wants to merge 13 commits into
Closed
Conversation
added 13 commits
September 4, 2026 12:30
…arked for deletion
… delete now deletes model if present
…ons for has_many relationships
The first test is on the blogger schema and the second test is self referential on the film store schema.
Member
|
Thanks for your contribution! However, there are issues with our existing API design, and the API you built upon it also has some semantic problems. I’d prefer to address these together in a future refactor (see #3183). Before implementing it, I’d also like us to first discuss and reach a consensus on the API design. |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Problem
I started upgrading my project to use SeaORM 2.0 and was able to cut out a lot of code that the new
ActiveModelExallows. After looking more closely at the docs, I realized that the newActiveHasManydoes not have a way to represent “deleted” in its state. This was a huge problem for my project since it uses PATCH requests that send only the information needed to update. The goal of these kind of requests are to reduce the amount of database calls and processing needed.Description
I have introduced a third variant to the
ActiveHasManyenum calledMutate. This variant keeps track of models that need to be deleted and models that need to be saved. There are now two new functions exposed on each has many relationship:delete_{RELATION_NAME}&delete_existing_{RELATION_NAME}. The first function is designed to work if theActiveModelthat needs to be deleted is not loaded in, the second is meant to be used if theActiveModelthat needs to be deleted is loaded. Thepush_*functions on theActiveHasMany enumalso ensure that a model with the same primary key does not appear in the save and delete state at the same time.Notes
swap_removewhen deleting elements from the save/delete vectors so these operations stay fastfor active models with a large number of related entities. This comes with the caveat that elements in a
ActiveHasManyenum may not retain their order after performingpush_*operations.Checklist
Release Notes
ActiveHasManymodels to be marked as deleted.