1

Meteor v 1.10.1. I am using meteor-collection2@3.0.6 and using simpl-schema v1.5.7 (NPM package)

I have this schema:

import SimpleSchema from "simpl-schema";

Orders.schema = new SimpleSchema ({
  name: {
    type: String
  },
  items: {
    type: Array
  },
  "items.$": {
     type: Object,
     Blackbox: true
  },

  orderTax: {
    type: Number,
    optional: true,
    autoValue: function () {
      if(this.isInsert || this.isUpdate) {
        return 0.5
     }
  }
  total: {
    type: Number,
    optional: true,
    autoValue: function () {
      if(this.isInsert || this.isUpdate) {
        const tax = this.field('orderTax').value;
        // Here tax is undefined
     }
    } 

})

orderTax is not sent as part of the object for simple-schema clean(), and yes that is the expected behavior, orderTax should only be computed for by the autoValue function on orderTax.

How do I use the autoValue computed from orderTax in total autoValue computation?

This setup works with earlier version of collection2 and earlier version aldeed:simple-schema (not NPM package)

  • When you insert a document with an arbitrary value for `orderTax` it will work. – Jankapunkt Apr 13 '20 at 14:06
  • Thanks @Jankapunkt, that will work, but for my use case, I would not be able to use that as a solution – dejibimbola Apr 13 '20 at 17:15
  • I thought so. Actually this seems to be a bug since the documentation clearly states that it's possible when the fields are called in the order as declared, which is true in your case. You should create an issue in the repo and add this as example. – Jankapunkt Apr 13 '20 at 17:23
  • Yes, I followed the order as described in the documentation. I created an issue almost the same time I asked the question on here. – dejibimbola Apr 13 '20 at 18:23

0 Answers0