overwrite new indexes with previous json value

This commit is contained in:
AJ ONeal 2016-03-26 17:03:19 -04:00
parent 91a59fa5ad
commit ce430e63c0
1 changed files with 9 additions and 2 deletions

View File

@ -193,8 +193,15 @@ function wrap(db, dir, dbsMap) {
delete row[idname];
Object.keys(row).forEach(function (fieldname) {
// TODO warn if overriding proper field? (shouldn't be possible)
obj[camelCase(fieldname)] = row[fieldname];
// Ideally it shouldn't be possible to overriding a former proper column,
// but when a new indexable field is added, the old value is still in json
// TODO one-time upgrade of all rows when a new column is added
if (null === row[fieldname] || 'undefined' === typeof row[fieldname] || '' === row[fieldname]) {
obj[camelCase(fieldname)] = row[fieldname] || obj[camelCase(fieldname)] || row[fieldname];
}
else {
obj[camelCase(fieldname)] = row[fieldname];
}
});
return obj;