mongoosejs / mongoose-lean-getters

Apply getters on lean() documents: https://mongoosejs.com/docs/tutorials/lean.html
Apache License 2.0
10 stars 15 forks source link

Fix: Handle discriminators with explicit values #31

Closed MarkParnwell closed 8 months ago

MarkParnwell commented 1 year ago

Summary

When using discriminators with explicit values (e.g., Base.discriminator('Child', ChildSchema, 'ExplicitValue')), the child schema can't be resolved correctly leading to an error "Cannot read properties of undefined (reading 'eachPath')" when using lean getters.

This change resolves the child schema using its explicit discriminator value if present, otherwise using its model name as is the default behaviour.

Related to #26

Examples

Added test should call getters on schemas with discriminator using explicit value