Skip to content

oneOf(Object, Number) somehow blocks all updates #428

@Twisterking

Description

@Twisterking

I have the following key in my schema:

priceInfo: {
  type: SimpleSchema.oneOf(Object, Number),
  blackbox: true,
  optional: true
}

In my app I have the following "upsert" logic:

if (this.currentPrice && this.currentPrice.isPromo) {
  let $setPrice = { priceInfo: price };
  if(typeof unit == 'string') {
    $setPrice = { [`priceInfo.${unit}`]: price };
  }
  Prices.update({ _id: this.currentPrice._id }, { $set: $setPrice })
} else {
  let priceInfo = price;
  if(typeof unit == 'string') {
    priceInfo = {};
    priceInfo[unit] = price;
  }
  Prices.insert({
    itemId: item._id,
    supplierId: currentSupplier._id,
    updated_at: new Date(),
    priceInfo,
    validity: {
      promoId: listId
    }
  });
}

This completely breaks it, as no update is possible with the following error:

Uncaught Error: After filtering out keys not in the schema, your modifier is now empty

Can anyone help? My code is correct (I think), without the schema everything works just fine.

best, Patrick

Metadata

Metadata

Assignees

No one assigned

    Labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions