Meteor-Community-Packages / meteor-simple-schema

Meteor integration package for simpl-schema
https://github.com/Meteor-Community-Packages/meteor-simple-schema
MIT License
919 stars 161 forks source link

"must be an object" error even though typeof() returns Object #734

Closed andregoldstein closed 6 years ago

andregoldstein commented 6 years ago

Hi there, I've seen a few more historic issues relating to Object errors but I'm running into an issue where I'm trying in insert a basic Object not an array of Objects as below:

ProductItemschema = new SimpleSchema({

  animalId:
    type: String

  animal:
    type: Object
    blackbox: true

})

I'm passing in animal which is a direct call from a findOne() query but this doesn't seem to be passing validation. Would you have any possible pointers? Thanks

andregoldstein commented 6 years ago

Update:

I think I've tracked it down, I think because the findOne object is returning a multi-dimensional object, when I test with a single-level Object, it seems to pass. I don't actually need that depth so I'll transform the object before validation.

Though not sure if blackbox: true is supposed to allow this. Thanks

andregoldstein commented 6 years ago

Hmm actually, it appears to be returning a Document object (sorry about the trail here)

Document {
  _id: ...
}

Using Object.assign would appear to resolve this: (CS)

animal = Object.assign {}, Animals.findOne item.animal._id
aldeed commented 6 years ago

The Meteor SimpleSchema package is no longer maintained other than critical fixes to keep it running with each latest Meteor release. Closing non-critical issues in this repo. Anyone who cares about this may do one or more of the following: