question-mark
Stuck on an issue?

Lightrun Answers was designed to reduce the constant googling that comes with debugging 3rd party libraries. It collects links to all the places you might be looking at while hunting down a tough bug.

And, if you’re still stuck at the end, we’re happy to hop on a call to see how we can help out.

Should pick() everything under array or object when picking array or object

See original GitHub issue

Howdy,

As mentioned in the title, to reproduce the issue, simply create a brand new Meteor project, remove all files cept .meteor, remove autopublish and insecure, add aldeed:simple-schema. Then add a single js file naming it whatever you want with the following contents:

MainSchema = new SimpleSchema({
  stringArray: {
    type: [String]
  }
});

DerivedSchema = MainSchema.pick('stringArray');

Try to run meteor in that directory and see it errors:

W20150307-22:42:49.991(8)? (STDERR)           
W20150307-22:42:49.993(8)? (STDERR) /home/hellyna/.local/lib/meteor/dev_bundle/server-lib/node_modules/fibers/future.js:173
W20150307-22:42:49.993(8)? (STDERR)                         throw(ex);
W20150307-22:42:49.993(8)? (STDERR)                               ^
W20150307-22:42:50.046(8)? (STDERR) Error: Invalid definition for stringArray.$ field.
W20150307-22:42:50.046(8)? (STDERR)     at packages/aldeed:simple-schema/simple-schema.js:465:1
W20150307-22:42:50.046(8)? (STDERR)     at Function._.each._.forEach (packages/underscore/underscore.js:113:1)
W20150307-22:42:50.046(8)? (STDERR)     at [object Object].SimpleSchema (packages/aldeed:simple-schema/simple-schema.js:462:1)
W20150307-22:42:50.046(8)? (STDERR)     at [object Object].SimpleSchema.pick (packages/aldeed:simple-schema/simple-schema.js:657:1)
W20150307-22:42:50.046(8)? (STDERR)     at app/bug.js:7:28
W20150307-22:42:50.046(8)? (STDERR)     at app/bug.js:10:3
W20150307-22:42:50.046(8)? (STDERR)     at /home/hellyna/someproj/.meteor/local/build/programs/server/boot.js:205:10
W20150307-22:42:50.047(8)? (STDERR)     at Array.forEach (native)
W20150307-22:42:50.047(8)? (STDERR)     at Function._.each._.forEach (/home/hellyna/.local/lib/meteor/dev_bundle/server-lib/node_modules/underscore/underscore.js:79:11)
W20150307-22:42:50.047(8)? (STDERR)     at /home/hellyna/someproj/.meteor/local/build/programs/server/boot.js:116:5

Issue Analytics

  • State:closed
  • Created 9 years ago
  • Comments:6

github_iconTop GitHub Comments

1reaction
Pagebakerscommented, Apr 4, 2016

Having issues with this aswel, in combination with AutoForm

var subSchema = new SimpleSchema({
  field1: {
   type: String
  },
  field2: {
   type: String
  }
});
var schema = new SimpleSchema({
  field: {
    type: [subSchema]
  }
});

var pickedSchema = schema.pick('field', 'field.$', 'field.$.field1', 'field.$.field2');
{{> quickForm schema=pickedSchema}}

Now it creates an afArrayField for ‘field’, afObjectField for ‘field.$’ and afQuickFields for ‘field2’ and ‘field2’

0reactions
aldeedcommented, Aug 24, 2016

Thanks for your patience. SimpleSchema 2.0.0-rc.1 is now released and should fix this bug.

There are a number of breaking changes when updating to 2.0, so be sure to check out the change log. If you use aldeed:collection2, you will need to use 2.10.0 or higher of that package in order to use SimpleSchema 2.0. If you use autoform, it is not yet updated to work with SimpleSchema 2.0, but hopefully soon.

SimpleSchema is now an isomorphic NPM package, so you can check out the updated readme and file issues over at the other repo. The Meteor wrapper package will exist for now but eventually I will probably deprecate support for it.

This is still a beta/RC and I do expect people will find issues, so use with caution. Production use is not yet recommended. That said, there are more and better unit tests than ever before, and the codebase should be much easier for others to read through and debug quickly.

Read more comments on GitHub >

github_iconTop Results From Across the Web

Should pick() everything under array or object when ... - GitHub
You need to pick the array item field, too. We could possibly have it do this automatically to prevent confusion. MainSchema.pick('stringArray ...
Read more >
equivalent of _.pick() but for array in Lo-dash - Stack Overflow
I think the map() + pick() approach is your best bet. You could compose the callback instead of creating an inline function however:...
Read more >
Array vs Set vs Map vs Object — Real-time use cases in ...
So with that introduction let's jump into using choosing javascript's built-in objects(Array, Object, Set and Map) based on operations we wish to use...
Read more >
Lodash _.pick() Method - GeeksforGeeks
Lodash helps in working with arrays, strings, objects, numbers, etc. The _.pick() method is used to return a copy of the object that...
Read more >
How to Use Array and Object Destructuring in JavaScript
First, we will discuss the destructuring assignment with arrays. Then we will move on to object destructuring. Let's get started. Basic Array ......
Read more >

github_iconTop Related Medium Post

No results found

github_iconTop Related StackOverflow Question

No results found

github_iconTroubleshoot Live Code

Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free

github_iconTop Related Reddit Thread

No results found

github_iconTop Related Hackernoon Post

No results found

github_iconTop Related Tweet

No results found

github_iconTop Related Dev.to Post

No results found

github_iconTop Related Hashnode Post

No results found