Meteor-Community-Packages / meteor-collection-hooks

Meteor Collection Hooks
https://atmospherejs.com/matb33/collection-hooks
MIT License
657 stars 92 forks source link

before.insert won't run before collection2 schema check on server side when calling via method #167

Open DaxChen opened 8 years ago

DaxChen commented 8 years ago

Hi, @matb33

Here's a repo to reproduce the error

When inserting inside meteor method, only client side runs the before.insert hook before collection2 's schema check. Server side won't run the hook, and fails the schema check. Error message:

Exception while invoking method 'insertTest' Error: Created at is required
I20151123-01:04:26.343(8)?     at getErrorObject (packages/aldeed_collection2/packages/aldeed_collection2.js:425:1)
I20151123-01:04:26.343(8)?     at [object Object].doValidate (packages/aldeed_collection2/packages/aldeed_collection2.js:408:1)
I20151123-01:04:26.343(8)?     at [object Object].Mongo.Collection.(anonymous function) [as insert] (packages/aldeed_collection2/packages/aldeed_collection2.js:177:1)
I20151123-01:04:26.343(8)?     at [object Object].Meteor.methods.insertTest (collection-hook-serverside-test.js:33:12)
I20151123-01:04:26.343(8)?     at maybeAuditArgumentChecks (livedata_server.js:1698:12)
I20151123-01:04:26.343(8)?     at livedata_server.js:708:19
I20151123-01:04:26.343(8)?     at [object Object]._.extend.withValue (packages/meteor/dynamics_nodejs.js:56:1)
I20151123-01:04:26.344(8)?     at livedata_server.js:706:40
I20151123-01:04:26.344(8)?     at [object Object]._.extend.withValue (packages/meteor/dynamics_nodejs.js:56:1)
I20151123-01:04:26.344(8)?     at livedata_server.js:704:46
I20151123-01:04:26.344(8)? Sanitized and reported to the client as: Created at is required [400]

Am I doing something wrong? Or is this a bug?

Thanks! YuHuaiChen

huevoncito commented 8 years ago

Looks like a load order issue. See https://github.com/matb33/meteor-collection-hooks/issues/153

beverlycodes commented 8 years ago

Unfortunately, changing the order of the dependencies inside my package doesn't fix this. Anyone have another workaround? Not being able to use collection-hooks and collection2 together in Meteor methods would lead to a pretty significant setback in the app I'm working on.

yogiben commented 8 years ago

@ryanfields did you figure this out?

@huevoncito it's definitely not a load order

beverlycodes commented 8 years ago

@yogiben Nope. I've stopped using collection-hooks. I didn't really find any good alternatives though. I just do what I can to work around the need for hooks now.

nicooprat commented 8 years ago

Looks like schemas/hooks order is inverted between client and server side: #154.

ferjep commented 4 months ago

This issue is still a thing, any updates?