Skip to content

Add ActiveHasMany Mutation (ability to delete) - #3195

Closed
Jacob-32587 wants to merge 13 commits into
SeaQL:masterfrom
Jacob-32587:Add-Active-Model-Mutation
Closed

Add ActiveHasMany Mutation (ability to delete)#3195
Jacob-32587 wants to merge 13 commits into
SeaQL:masterfrom
Jacob-32587:Add-Active-Model-Mutation

Conversation

@Jacob-32587

@Jacob-32587 Jacob-32587 commented Sep 7, 2026

Copy link
Copy Markdown

Problem

I started upgrading my project to use SeaORM 2.0 and was able to cut out a lot of code that the new ActiveModelEx allows. After looking more closely at the docs, I realized that the new ActiveHasMany does 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 ActiveHasMany enum called Mutate. 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 the ActiveModel that needs to be deleted is not loaded in, the second is meant to be used if the ActiveModel that needs to be deleted is loaded. The push_* functions on the ActiveHasMany enum also ensure that a model with the same primary key does not appear in the save and delete state at the same time.

Notes

  • I chose to use swap_remove when deleting elements from the save/delete vectors so these operations stay fast
    for active models with a large number of related entities. This comes with the caveat that elements in a ActiveHasMany enum may not retain their order after performing push_* operations.

Checklist

  • I have read the AI Policy and confirm that this contribution complies with it.

Release Notes

  • Add the ability for ActiveHasMany models to be marked as deleted.

@Huliiiiii

Copy link
Copy Markdown
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.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants