Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Invalid definition for status.$ field #3

Open
jdnichollsc opened this issue Dec 19, 2016 · 3 comments
Open

Invalid definition for status.$ field #3

jdnichollsc opened this issue Dec 19, 2016 · 3 comments

Comments

@jdnichollsc
Copy link

Hi guys,

I'm getting the following error:

W20161219-11:20:49.767(-5)? (STDERR) Error: Invalid definition for status.$ field.
W20161219-11:20:49.767(-5)? (STDERR)     at packages/aldeed_simple-schema.js:1429:13
W20161219-11:20:49.767(-5)? (STDERR)     at Function._.each._.forEach (packages/underscore.js:147:22)
W20161219-11:20:49.768(-5)? (STDERR)     at [object Object].SimpleSchema (packages/aldeed_simple-schema.js:1426:5)
W20161219-11:20:49.768(-5)? (STDERR)     at [object Object].SimpleSchema.pick (packages/aldeed_simple-schema.js:1632:10)
W20161219-11:20:49.769(-5)? (STDERR)     at meteorInstall.imports.api.contracts.methods.js (imports/api/contracts/methods.js:39:30)
W20161219-11:20:49.770(-5)? (STDERR)     at fileEvaluate (packages/modules-runtime.js:181:9)
W20161219-11:20:49.770(-5)? (STDERR)     at Module.require (packages/modules-runtime.js:106:16)
W20161219-11:20:49.770(-5)? (STDERR)     at Module.Mp.import (/Users/juannicholls/.meteor/packages/modules/.0.7.7.yjn28g++os+web.browser+web.cordova/np
m/node_modules/reify/lib/runtime.js:70:16)
W20161219-11:20:49.770(-5)? (STDERR)     at meteorInstall.imports.startup.server.api.js (imports/startup/server/api.js:1:1)
W20161219-11:20:49.771(-5)? (STDERR)     at fileEvaluate (packages/modules-runtime.js:181:9)

And my code is

export const updateContract = new ValidatedMethod({
  name: 'contracts.update',
  mixins: [simpleSchemaMixin],
  schema: [
    CONTRACT_ID_ONLY,
    Contracts.simpleSchema().pick(['status']),
  ],
  schemaValidatorOptions: { clean: true, filter: false },
  run({ contractId, status }) {
    console.log(status);
    Contracts.update(contractId, {
      $set: {
        status: status
      },
    });
  }
});

Thanks in advance, Nicholls

@rhettlivingston
Copy link
Owner

I believe SimpleSchema is throwing an exception at simple-schema.js#L457 while trying to "pick" the status field because the schema definition for your status field has failed a validation test. Perhaps some field in that schema definition has the wrong name or type?

@lirbank
Copy link

lirbank commented Feb 21, 2017

@jdnichollsc I had the exact same issue (error at packages/aldeed_simple-schema.js:1429:13).

Got .pick() working with arrays after I switched the schema definition from:

  items: {
    type: [Object],
    label: 'Items',
    optional: true,
  },
  'items.$.sku': {
    type: String,
    label: 'SKU',
  },

to:

  items: {
    type: Array,
    optional: true,
  },
  'items.$': {
    type: Object,
    optional: true,
  },
  'items.$.description': {
    type: String,
  },

Which is essentially the same thing.

@lirbank
Copy link

lirbank commented Feb 21, 2017

Oh, just saw this in the docs

NOTE: When using pick on a field of type Array you also need to pick the array item field.

See https://github.com/aldeed/meteor-simple-schema#extracting-simpleschemas

My schema change above was probably not the fix, but rather that I started picking also the items.$ field.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

3 participants