tywalch/electrodb

Default values in nested attributes

tywalch opened this issue · 0 comments

Currently, for nested "map" attributes, the attribute property default is only evaluated when its parent is provided by the user via a put or create method. In its current implementation, a user can defined an empty object as a default value on their map attribute, however that will not cause a the object to then be populated with the default values of the nested attributes on that "map". This can be counter intuitive when from a user experience when the map attribute will always exist for a given entity, and and the only way to apply defaults would be to supply an empty object.

A better approach would be evaluate default values outward, starting with root maps and extending to nested attributes. If a default value (or callback) is not supplied or returns undefined, then further nested defaults will not be applied.

An example for this implementation can be found here.