orionjs/orioncms

When removing object from array, left with null instead of complete removal at index

Opened this issue · 1 comments

When I remove something like the below:
pasted_image_8_18_16__12_31_am
it looks like it get's removed, but when I go back to the document I see it as a blank entry
pasted_image_8_18_16__12_33_am
when checking in the database, I see that null is left behind instead of the array element being removed
pasted_image_8_18_16__12_34_am

it really should remove the entire element of the array, not replace it with null

because this package depends on https://github.com/aldeed/meteor-simple-schema#validating-data I realized I could just delete those null values upon save with a simple one-liner as follows in the autoValue function

Layouts.attachSchema(new SimpleSchema({
  'orgID': {
    'type': String,
    'label': 'Unique Id',
    'max': 50,
  },
  'categoryIds': {
    'type': [String],
    'label': 'Category Ids the schema applies to',
  },
  'graphs': {
    type: [ChartSchema],
    'autoValue': function() {
      // remove the null in array on update https://github.com/orionjs/orion/issues/429
      return this.value.filter(value => value !== null);
    },
  },
}));

Although it seems this issue presents itself in the actual dependency, I thought it would be helpful to have a post here as well for future reference