clear() not working correctly with nested schema objects
scotthovestadt opened this issue · comments
From blnprasad:
Hi,
With new changes i'm seeing some strage behaviour where the following code corrupting passed value field in typecast function.
schemaObject = originalValue;
schemaObject.clear() ->> this statment is causing "value" and "properties" to be corrupted in some nested schmea object cases which is resulting into pouplating of schemaObject with undefined instead of default values.
If above is not clear from code review then i'll try to get example schmea for above.
Thanks,
BLN
Please find the below problematic schema.
var schemaObject = require('node-schema-object');
var type_string = {type: String};
var sample = new schemaObject({
"_array": {type: Array, arrayType: String},
"hi": String,
"hello": String,
});
var _ext_sample = new schemaObject({
"_sample": sample,
"_hi": String,
});
var _ext_ext_sample = new schemaObject({
"_ext_sample": _ext_sample,
"_hello": String,
});
var dev = new _ext_ext_sample({"_hello": "123",
" _ext_sample":
{"_sample": {
"hi": "123",
"hello": "456",
"_array": ["1", "2", "3"]
}
}
});
console.log(dev.toObject());
The reason that this isn't working is because when you're constructing the object, you've set the key to:
" _ext_sample"
Notice the extra space before the underscore.
Remove the space and the object is set correctly.
That correct. The above schema example is wrong. I can't give my schema since its from company project. I debugged and found that below is causing issue in my case.
i was using {type: Object} in one of my schema object and below code in clearField function is causing issue.
if(properties.type === 'object') {
this[properties.name].clear() --> this function is not avaible for simple object
I found to be working fine if i guard above call with .isFunction
if (.isFunction(this[properties.name].clear))
this[properties.name].clear()
Pleae check above and let me know if above is valid or some thing i need to verify my side.
Thanks,
BLN
I'll make this change and write a test for it today.
Thanks.
On Fri, Nov 14, 2014 at 1:37 AM, scotthovestadt notifications@github.com
wrote:
I'll make this change and write a test for it today.
—
Reply to this email directly or view it on GitHub
#12 (comment)
.