Skip to content

Generate Active Model from Two Models' Differences #3067

Description

@SamuNatsu

Motivation

The model is serialized then edited by an external editor, which would deserialize back to a new model after editing.

Do a full update is ok, while find the diffs between old and new model for on-demand updating is more clever.

Proposed Solutions

Provide a new method for derive macros like fn create_diff_active_model(old_model: &Model) -> ActiveModel is enough.

Additional Information

Activity

  1. mansiverma897993 commented on Jun 7, 2026

    @mansiverma897993

    @SamuNatsu can you assign this issue to me ?? or I can directly raise PR ?

  2. SamuNatsu commented on Jun 7, 2026

    @SamuNatsu
    Author

    @SamuNatsu can you assign this issue to me ?? or I can directly raise PR ?

    I'm not the maintainer of the project, so assigning the issue to you is technically impossible :(

    Raise PR with a reference #3067 is enough

  3. Expurple commented on Jun 8, 2026

    @Expurple
    Member

    I just encountered a case where this would be useful at my job! This is a great idea.

    Until it's implemented by a SeaORM derive macro, I suggest using "Destructure as a Reminder" idiom to make sure to cover all fields in your manual implementation. Mine looks like this:

    fn merge_models_and_mark_changes(old: foo::Model, new: foo::Model) -> foo::ActiveModel {
      let mut result = old.into_active_model();
      // Intentionally unpack so that we get warnings for unused fields
      // and a compiler error here when a new fields is added.
      let foo::ActiveModel { bar, baz } = &mut result;
      bar.set_ne(new.bar);
      baz.set_ne(new.baz);
      result
    }

    Also note that a reference (old_model: &Model) in your proposed signature is a tradeoff. It requires you to clone out the value when it's Unchanged. Which is actually more work when you no longer need the old model and are fine with consuming it.

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

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions