Skip to content

Getter doesn't work on a nested single subdocument #45

Open
@nathan-knight

Description

@nathan-knight

I think this was introduced by #43
I have a subdocument that is transformed by the getter into a single object that should be assigned to the original document:

{
  _id: false,
  type: {
    amount: {
      type: mongoose.Types.Decimal128,
      required: true,
    },
    currency: {
      type: String,
      required: true,
    },
  },

  set: transformCurrencyToDbStructure,
  get: transformCurrencyFromDbStructure,
}

This worked before on 2.0.1 but after updating to 2.2.1 it just returns the original subdocument without applying the getter.

applyGettersToDoc.call(this, schematype.schema, val);

Upon further investigation, it reaches this point and then tries to apply getters to the fields of the subdocument (passing along the transformed subdocument which is now a totally different structure) and then discards the transformed value (val) instead of assigning it to the document.

Locally I've patched it to do mpath.set(path, val, doc); in this case too which has resolved it but I am not certain whether this may have undesired side effects. I can put up a PR for this.

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions