Automattic / Automattic/mongoose
Custom setter on MixedType doesn't know path when setting nested property
- Dominant language
- JavaScript
- Stars
- 27.5k
- Forks
- 4k
- Avg merge
- 2d 7h
- Merged PRs (30d)
- 35
Description
This is a follow on related to #1418 (Setting nested path into attribute of Types.Mixed is ignored).
I have a MixedType property with a customer setter defined. When setting a nested property of that MixedType property, the setter is passed the value being set but doesn't receive any information about the path being set.
This gist demonstrates: https://gist.github.com/asalant/5423400
The reason this is an issue is that if I want to do any preprocessing of the set value, I need to know the path for the value - is it resetting the whole MixedType or setting a child property? It's interesting that the second argument appears to be the schema definition for the property.
Looking at mongoose source I did not see an obvious way to get this value to the setter.
Alon
(https://groups.google.com/forum/?fromgroups=#!topic/mongoose-orm/Vo2HdUAGS6U)
Contributor guide
Research direction
Start with the linked gist and trace the MixedType custom-setter handling in the Mongoose source, comparing whole-property assignment with nested-property assignment. Confirm how the setter arguments differ and determine where the nested path is lost. Done means a custom setter can distinguish those cases and the demonstrated behavior is covered by a regression test.
Written by the indexing model from the issue text.
Assessment
- Tech stack
- javascript, mongodb, nodejs
- Domain
- backend, databases
- Issue type
- Bug
- Difficulty
- 4/5
- Estimated time
- 3-5 days
- Activity status
- Stale
- Clarity
- Mostly clear
- Newbie friendliness
- 35/100