meteor-collection-hooks icon indicating copy to clipboard operation
meteor-collection-hooks copied to clipboard

Question: Order of collection before hook, autoform before hook, and simple schema check

Open minfawang opened this issue 10 years ago • 6 comments

From https://github.com/aldeed/meteor-autoform/issues/766#issuecomment-84171424:

  1. Validate against form schema (prevalidate)
  2. Run before hooks if valid
  3. Validate against collection schema
  4. Call method if valid

This is the order of Autoform before hook and Simple Schema validation. I'm wondering how does Collection before hook fit in this sequence? Is it definitive or indefinitive?

minfawang avatar Sep 10 '15 01:09 minfawang

Hi, any news on this one? I also want to use collectionHooks with autoform.

I guess the hooks are triggered with every database access which will happen in position 5?

thebarty avatar Sep 25 '15 07:09 thebarty

This seems like a common use case as there are 3 open issues right now asking the same thing. I suppose we could use simple schema's autoValue or defaultValue, but I like how straight forward collection hooks are and the idea of keeping everything in one place. I'm surprised this doesn't play nice with simple schema since I see @aldeed is a contributor.

Are there any suggestions for using before.insert hooks and the simple schema package?

BradRyan avatar Dec 21 '15 21:12 BradRyan

I expect the collection before hook probably comes either after or before the validation, depending on which order you list the two packages in your dependency file. This is one of the unavoidable issues I think unless MDG adds core support for hooks.

aldeed avatar Dec 22 '15 13:12 aldeed

@aldeed I think is not a load order issue, because I have collection-hooks package loading before the others from the first time, and have the same problem, the schema validation seems to avoid triggering the hook.

samuelluis avatar Apr 19 '16 14:04 samuelluis

I've just used optional: true on fields which hooks are adding defaults for. It's not ideal though.

aramk avatar May 21 '16 05:05 aramk

@aramk Thanks. This worked for me.

Though, I expected simple schema to throw a not in schema error.

rendered-monkey avatar Oct 05 '16 16:10 rendered-monkey