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

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

Closed
Hellyna opened this issue Mar 7, 2015 · 6 comments
Closed

Comments

@Hellyna
Copy link

Hellyna commented Mar 7, 2015

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
@aldeed
Copy link
Collaborator

aldeed commented Mar 7, 2015

You need to pick the array item field, too. We could possibly have it do this automatically to prevent confusion.

MainSchema.pick('stringArray', 'stringArray.$');

@delgermurun
Copy link

Please at least document it, in the meantime.

@fabyeah
Copy link

fabyeah commented May 22, 2015

+1 needs documentation if it isn't done automatically.

@aldeed aldeed changed the title Cannot schema.pick() a field which contains type [String] Should pick() everything under array or object when picking array or object Nov 10, 2015
@paulbalomiri
Copy link

Also, when picking the list content schema list.$ there is a silent bug:

s=new SimpleSchema
 l: {type:Array}
s2= s.pick('l.$')

s2.schema().l.type is now Object() instead of Array()

@Pagebakers
Copy link

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'

@aldeed
Copy link
Collaborator

aldeed commented 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.

@aldeed aldeed closed this as completed Aug 24, 2016
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

No branches or pull requests

6 participants