Closed davidkell closed 5 years ago
@davidkell Hi, indeed there is no way to do it, maybe only if data provided to sanitizer would contain a kind
, but probably it's not what you look for.
Feel free to contribute - at first look, only what you need is to call sanitizer with this
context.
here https://github.com/Nozbe/WatermelonDB/blob/master/src/decorators/json/index.js#L42 and here https://github.com/Nozbe/WatermelonDB/blob/master/src/decorators/json/index.js#L45
sanitizer.call(this, json)
but I haven't tested this solution.
Thanks, will have a look at this.
We have a use case with the following parameters:
MyEntity
MyEntity
has akind
field (an Enum) and acontent
field (JSON)content
field depends on thekind
We want to validate and sanitise the JSON field using the sanitise content field. Is it possible to provide information on the
kind
to the sanitise content function for thecontent
JSON field? (We couldn't find a way.)A more concrete example:
(Another solution would be to have separate model for each distinct kind. Unfortunately, this would not work as we need to dynamically generate new kinds.)