Skip to content

Mutators appear to be broken. Works on initial insert/save but not on updates #1818

@vesper8

Description

@vesper8

Environment

No response

Reproduction

Please see description below

Describe the bug

I've created a very simple mutator that encrypts my string. The method of encryption itself does not matter in the context of this bug report.

  static mutators() {
    return {
      content: {
        set: (value) => {
          const encryptedValue = encryptData(value);
          console.log('content.set', value, encryptedValue);
          return encryptedValue;
        },
      },
    };
  }

When I create a new record:

          await useRepo(Requirement).save({
            id: 1,
            content: this.form.content,
          });

Then everything works fine. I can trace that my set mutator is being visited, the plainText is encrypted, and if I view my content with

        const requirement = useRepo(Requirement).find(1);

        console.log('requirement.content', requirement.content);

Then the value is indeed encrypted and life is good.

If I then update this existing requirement

Whether like this:

          await useRepo(Requirement)
            .find(1)
            .update({
              content: this.form.content,
            });

Or like this

          await useRepo(Requirement).save({
            id: 1,
            content: this.form.content,
          });

Then again I can trace that my set mutator is being visited. The set mutator does the encryption, however unlike when I created a new record, this time if I inspect the value with

        const requirement = useRepo(Requirement).find(1);

        console.log('requirement.content', requirement.content);

This time the value is plainText. It is not the encrypted value. So the mutator is "used" but somehow not applied on updates, only on inserts.

Additional context

No response

Logs

No response

Metadata

Metadata

Assignees

No one assigned

    Labels

    bugSomething isn't working

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions