meteor-collection-hooks
meteor-collection-hooks copied to clipboard
Question: Order of collection before hook, autoform before hook, and simple schema check
From https://github.com/aldeed/meteor-autoform/issues/766#issuecomment-84171424:
- Validate against form schema (prevalidate)
- Run before hooks if valid
- Validate against collection schema
- 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?
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?
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?
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 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.
I've just used optional: true on fields which hooks are adding defaults for. It's not ideal though.
@aramk Thanks. This worked for me.
Though, I expected simple schema to throw a not in schema error.