不要怂,就是干,撸起袖子干!

Commit a03a14ba by Stefan Kleeschulte

Improved validationFailed hook documentation, updated generated api docs

1 parent ea444d31
Showing with 53 additions and 36 deletions
<a name="hooks"></a> <a name="hooks"></a>
# Mixin Hooks # Mixin Hooks
[View code](https://github.com/sequelize/sequelize/blob/0de404640d4c71e2d1f1259356650dfb586a248b/lib/hooks.js#L39) [View code](https://github.com/sequelize/sequelize/blob/ea444d318402f5de7f13f2c8dd6512fe0b8a38d8/lib/hooks.js#L39)
Hooks are function that are called before and after (bulk-) creation/updating/deletion and validation. Hooks can be added to you models in three ways: Hooks are function that are called before and after (bulk-) creation/updating/deletion and validation. Hooks can be added to you models in three ways:
...@@ -38,7 +38,7 @@ Model.afterBulkUpdate(function () {}) ...@@ -38,7 +38,7 @@ Model.afterBulkUpdate(function () {})
<a name="addhook"></a> <a name="addhook"></a>
## `addHook(hooktype, [name], fn)` ## `addHook(hooktype, [name], fn)`
[View code](https://github.com/sequelize/sequelize/blob/0de404640d4c71e2d1f1259356650dfb586a248b/lib/hooks.js#L160) [View code](https://github.com/sequelize/sequelize/blob/ea444d318402f5de7f13f2c8dd6512fe0b8a38d8/lib/hooks.js#L161)
Add a hook to the model Add a hook to the model
...@@ -56,7 +56,7 @@ __Aliases:__ hook ...@@ -56,7 +56,7 @@ __Aliases:__ hook
<a name="removehook"></a> <a name="removehook"></a>
## `removeHook(hookType, name)` ## `removeHook(hookType, name)`
[View code](https://github.com/sequelize/sequelize/blob/0de404640d4c71e2d1f1259356650dfb586a248b/lib/hooks.js#L179) [View code](https://github.com/sequelize/sequelize/blob/ea444d318402f5de7f13f2c8dd6512fe0b8a38d8/lib/hooks.js#L180)
Remove hook from the model Remove hook from the model
...@@ -72,7 +72,7 @@ Remove hook from the model ...@@ -72,7 +72,7 @@ Remove hook from the model
<a name="hashook"></a> <a name="hashook"></a>
## `hasHook(hookType)` ## `hasHook(hookType)`
[View code](https://github.com/sequelize/sequelize/blob/0de404640d4c71e2d1f1259356650dfb586a248b/lib/hooks.js#L205) [View code](https://github.com/sequelize/sequelize/blob/ea444d318402f5de7f13f2c8dd6512fe0b8a38d8/lib/hooks.js#L206)
Check whether the mode has any hooks of this type Check whether the mode has any hooks of this type
...@@ -88,7 +88,7 @@ __Aliases:__ hasHooks ...@@ -88,7 +88,7 @@ __Aliases:__ hasHooks
<a name="beforevalidate"></a> <a name="beforevalidate"></a>
## `beforeValidate(name, fn)` ## `beforeValidate(name, fn)`
[View code](https://github.com/sequelize/sequelize/blob/0de404640d4c71e2d1f1259356650dfb586a248b/lib/hooks.js#L218) [View code](https://github.com/sequelize/sequelize/blob/ea444d318402f5de7f13f2c8dd6512fe0b8a38d8/lib/hooks.js#L219)
A hook that is run before validation A hook that is run before validation
...@@ -104,7 +104,7 @@ A hook that is run before validation ...@@ -104,7 +104,7 @@ A hook that is run before validation
<a name="aftervalidate"></a> <a name="aftervalidate"></a>
## `afterValidate(name, fn)` ## `afterValidate(name, fn)`
[View code](https://github.com/sequelize/sequelize/blob/0de404640d4c71e2d1f1259356650dfb586a248b/lib/hooks.js#L225) [View code](https://github.com/sequelize/sequelize/blob/ea444d318402f5de7f13f2c8dd6512fe0b8a38d8/lib/hooks.js#L226)
A hook that is run after validation A hook that is run after validation
...@@ -118,9 +118,25 @@ A hook that is run after validation ...@@ -118,9 +118,25 @@ A hook that is run after validation
*** ***
<a name="validationfailed"></a>
## `validationFailed(name, fn)`
[View code](https://github.com/sequelize/sequelize/blob/ea444d318402f5de7f13f2c8dd6512fe0b8a38d8/lib/hooks.js#L234)
A hook that is run when validation fails
**Params:**
| Name | Type | Description |
| ---- | ---- | ----------- |
| name | String | |
| fn | Function | A callback function that is called with instance, options, error. Error is the SequelizeValidationError. If the callback throws an error, it will replace the original validation error. |
***
<a name="beforecreate"></a> <a name="beforecreate"></a>
## `beforeCreate(name, fn)` ## `beforeCreate(name, fn)`
[View code](https://github.com/sequelize/sequelize/blob/0de404640d4c71e2d1f1259356650dfb586a248b/lib/hooks.js#L232) [View code](https://github.com/sequelize/sequelize/blob/ea444d318402f5de7f13f2c8dd6512fe0b8a38d8/lib/hooks.js#L241)
A hook that is run before creating a single instance A hook that is run before creating a single instance
...@@ -136,7 +152,7 @@ A hook that is run before creating a single instance ...@@ -136,7 +152,7 @@ A hook that is run before creating a single instance
<a name="aftercreate"></a> <a name="aftercreate"></a>
## `afterCreate(name, fn)` ## `afterCreate(name, fn)`
[View code](https://github.com/sequelize/sequelize/blob/0de404640d4c71e2d1f1259356650dfb586a248b/lib/hooks.js#L239) [View code](https://github.com/sequelize/sequelize/blob/ea444d318402f5de7f13f2c8dd6512fe0b8a38d8/lib/hooks.js#L248)
A hook that is run after creating a single instance A hook that is run after creating a single instance
...@@ -152,7 +168,7 @@ A hook that is run after creating a single instance ...@@ -152,7 +168,7 @@ A hook that is run after creating a single instance
<a name="beforedestroy"></a> <a name="beforedestroy"></a>
## `beforeDestroy(name, fn)` ## `beforeDestroy(name, fn)`
[View code](https://github.com/sequelize/sequelize/blob/0de404640d4c71e2d1f1259356650dfb586a248b/lib/hooks.js#L248) [View code](https://github.com/sequelize/sequelize/blob/ea444d318402f5de7f13f2c8dd6512fe0b8a38d8/lib/hooks.js#L257)
A hook that is run before destroying a single instance A hook that is run before destroying a single instance
...@@ -169,7 +185,7 @@ __Aliases:__ beforeDelete ...@@ -169,7 +185,7 @@ __Aliases:__ beforeDelete
<a name="afterdestroy"></a> <a name="afterdestroy"></a>
## `afterDestroy(name, fn)` ## `afterDestroy(name, fn)`
[View code](https://github.com/sequelize/sequelize/blob/0de404640d4c71e2d1f1259356650dfb586a248b/lib/hooks.js#L257) [View code](https://github.com/sequelize/sequelize/blob/ea444d318402f5de7f13f2c8dd6512fe0b8a38d8/lib/hooks.js#L266)
A hook that is run after destroying a single instance A hook that is run after destroying a single instance
...@@ -186,7 +202,7 @@ __Aliases:__ afterDelete ...@@ -186,7 +202,7 @@ __Aliases:__ afterDelete
<a name="beforerestore"></a> <a name="beforerestore"></a>
## `beforeRestore(name, fn)` ## `beforeRestore(name, fn)`
[View code](https://github.com/sequelize/sequelize/blob/0de404640d4c71e2d1f1259356650dfb586a248b/lib/hooks.js#L265) [View code](https://github.com/sequelize/sequelize/blob/ea444d318402f5de7f13f2c8dd6512fe0b8a38d8/lib/hooks.js#L274)
A hook that is run before restoring a single instance A hook that is run before restoring a single instance
...@@ -202,7 +218,7 @@ A hook that is run before restoring a single instance ...@@ -202,7 +218,7 @@ A hook that is run before restoring a single instance
<a name="afterrestore"></a> <a name="afterrestore"></a>
## `afterRestore(name, fn)` ## `afterRestore(name, fn)`
[View code](https://github.com/sequelize/sequelize/blob/0de404640d4c71e2d1f1259356650dfb586a248b/lib/hooks.js#L273) [View code](https://github.com/sequelize/sequelize/blob/ea444d318402f5de7f13f2c8dd6512fe0b8a38d8/lib/hooks.js#L282)
A hook that is run after restoring a single instance A hook that is run after restoring a single instance
...@@ -218,7 +234,7 @@ A hook that is run after restoring a single instance ...@@ -218,7 +234,7 @@ A hook that is run after restoring a single instance
<a name="beforeupdate"></a> <a name="beforeupdate"></a>
## `beforeUpdate(name, fn)` ## `beforeUpdate(name, fn)`
[View code](https://github.com/sequelize/sequelize/blob/0de404640d4c71e2d1f1259356650dfb586a248b/lib/hooks.js#L280) [View code](https://github.com/sequelize/sequelize/blob/ea444d318402f5de7f13f2c8dd6512fe0b8a38d8/lib/hooks.js#L289)
A hook that is run before updating a single instance A hook that is run before updating a single instance
...@@ -234,7 +250,7 @@ A hook that is run before updating a single instance ...@@ -234,7 +250,7 @@ A hook that is run before updating a single instance
<a name="afterupdate"></a> <a name="afterupdate"></a>
## `afterUpdate(name, fn)` ## `afterUpdate(name, fn)`
[View code](https://github.com/sequelize/sequelize/blob/0de404640d4c71e2d1f1259356650dfb586a248b/lib/hooks.js#L287) [View code](https://github.com/sequelize/sequelize/blob/ea444d318402f5de7f13f2c8dd6512fe0b8a38d8/lib/hooks.js#L296)
A hook that is run after updating a single instance A hook that is run after updating a single instance
...@@ -250,7 +266,7 @@ A hook that is run after updating a single instance ...@@ -250,7 +266,7 @@ A hook that is run after updating a single instance
<a name="beforebulkcreate"></a> <a name="beforebulkcreate"></a>
## `beforeBulkCreate(name, fn)` ## `beforeBulkCreate(name, fn)`
[View code](https://github.com/sequelize/sequelize/blob/0de404640d4c71e2d1f1259356650dfb586a248b/lib/hooks.js#L294) [View code](https://github.com/sequelize/sequelize/blob/ea444d318402f5de7f13f2c8dd6512fe0b8a38d8/lib/hooks.js#L303)
A hook that is run before creating instances in bulk A hook that is run before creating instances in bulk
...@@ -266,7 +282,7 @@ A hook that is run before creating instances in bulk ...@@ -266,7 +282,7 @@ A hook that is run before creating instances in bulk
<a name="afterbulkcreate"></a> <a name="afterbulkcreate"></a>
## `afterBulkCreate(name, fn)` ## `afterBulkCreate(name, fn)`
[View code](https://github.com/sequelize/sequelize/blob/0de404640d4c71e2d1f1259356650dfb586a248b/lib/hooks.js#L301) [View code](https://github.com/sequelize/sequelize/blob/ea444d318402f5de7f13f2c8dd6512fe0b8a38d8/lib/hooks.js#L310)
A hook that is run after creating instances in bulk A hook that is run after creating instances in bulk
...@@ -282,7 +298,7 @@ A hook that is run after creating instances in bulk ...@@ -282,7 +298,7 @@ A hook that is run after creating instances in bulk
<a name="beforebulkdestroy"></a> <a name="beforebulkdestroy"></a>
## `beforeBulkDestroy(name, fn)` ## `beforeBulkDestroy(name, fn)`
[View code](https://github.com/sequelize/sequelize/blob/0de404640d4c71e2d1f1259356650dfb586a248b/lib/hooks.js#L310) [View code](https://github.com/sequelize/sequelize/blob/ea444d318402f5de7f13f2c8dd6512fe0b8a38d8/lib/hooks.js#L319)
A hook that is run before destroying instances in bulk A hook that is run before destroying instances in bulk
...@@ -299,7 +315,7 @@ __Aliases:__ beforeBulkDelete ...@@ -299,7 +315,7 @@ __Aliases:__ beforeBulkDelete
<a name="afterbulkdestroy"></a> <a name="afterbulkdestroy"></a>
## `afterBulkDestroy(name, fn)` ## `afterBulkDestroy(name, fn)`
[View code](https://github.com/sequelize/sequelize/blob/0de404640d4c71e2d1f1259356650dfb586a248b/lib/hooks.js#L319) [View code](https://github.com/sequelize/sequelize/blob/ea444d318402f5de7f13f2c8dd6512fe0b8a38d8/lib/hooks.js#L328)
A hook that is run after destroying instances in bulk A hook that is run after destroying instances in bulk
...@@ -316,7 +332,7 @@ __Aliases:__ afterBulkDelete ...@@ -316,7 +332,7 @@ __Aliases:__ afterBulkDelete
<a name="beforebulkrestore"></a> <a name="beforebulkrestore"></a>
## `beforeBulkRestore(name, fn)` ## `beforeBulkRestore(name, fn)`
[View code](https://github.com/sequelize/sequelize/blob/0de404640d4c71e2d1f1259356650dfb586a248b/lib/hooks.js#L327) [View code](https://github.com/sequelize/sequelize/blob/ea444d318402f5de7f13f2c8dd6512fe0b8a38d8/lib/hooks.js#L336)
A hook that is run before restoring instances in bulk A hook that is run before restoring instances in bulk
...@@ -332,7 +348,7 @@ A hook that is run before restoring instances in bulk ...@@ -332,7 +348,7 @@ A hook that is run before restoring instances in bulk
<a name="afterbulkrestore"></a> <a name="afterbulkrestore"></a>
## `afterBulkRestore(name, fn)` ## `afterBulkRestore(name, fn)`
[View code](https://github.com/sequelize/sequelize/blob/0de404640d4c71e2d1f1259356650dfb586a248b/lib/hooks.js#L335) [View code](https://github.com/sequelize/sequelize/blob/ea444d318402f5de7f13f2c8dd6512fe0b8a38d8/lib/hooks.js#L344)
A hook that is run after restoring instances in bulk A hook that is run after restoring instances in bulk
...@@ -348,9 +364,9 @@ A hook that is run after restoring instances in bulk ...@@ -348,9 +364,9 @@ A hook that is run after restoring instances in bulk
<a name="beforebulkupdate"></a> <a name="beforebulkupdate"></a>
## `beforeBulkUpdate(name, fn)` ## `beforeBulkUpdate(name, fn)`
[View code](https://github.com/sequelize/sequelize/blob/0de404640d4c71e2d1f1259356650dfb586a248b/lib/hooks.js#L342) [View code](https://github.com/sequelize/sequelize/blob/ea444d318402f5de7f13f2c8dd6512fe0b8a38d8/lib/hooks.js#L351)
A hook that is run after updating instances in bulk A hook that is run before updating instances in bulk
**Params:** **Params:**
...@@ -364,7 +380,7 @@ A hook that is run after updating instances in bulk ...@@ -364,7 +380,7 @@ A hook that is run after updating instances in bulk
<a name="afterbulkupdate"></a> <a name="afterbulkupdate"></a>
## `afterBulkUpdate(name, fn)` ## `afterBulkUpdate(name, fn)`
[View code](https://github.com/sequelize/sequelize/blob/0de404640d4c71e2d1f1259356650dfb586a248b/lib/hooks.js#L349) [View code](https://github.com/sequelize/sequelize/blob/ea444d318402f5de7f13f2c8dd6512fe0b8a38d8/lib/hooks.js#L358)
A hook that is run after updating instances in bulk A hook that is run after updating instances in bulk
...@@ -380,7 +396,7 @@ A hook that is run after updating instances in bulk ...@@ -380,7 +396,7 @@ A hook that is run after updating instances in bulk
<a name="beforefind"></a> <a name="beforefind"></a>
## `beforeFind(name, fn)` ## `beforeFind(name, fn)`
[View code](https://github.com/sequelize/sequelize/blob/0de404640d4c71e2d1f1259356650dfb586a248b/lib/hooks.js#L356) [View code](https://github.com/sequelize/sequelize/blob/ea444d318402f5de7f13f2c8dd6512fe0b8a38d8/lib/hooks.js#L365)
A hook that is run before a find (select) query A hook that is run before a find (select) query
...@@ -396,7 +412,7 @@ A hook that is run before a find (select) query ...@@ -396,7 +412,7 @@ A hook that is run before a find (select) query
<a name="beforefindafterexpandincludeall"></a> <a name="beforefindafterexpandincludeall"></a>
## `beforeFindAfterExpandIncludeAll(name, fn)` ## `beforeFindAfterExpandIncludeAll(name, fn)`
[View code](https://github.com/sequelize/sequelize/blob/0de404640d4c71e2d1f1259356650dfb586a248b/lib/hooks.js#L363) [View code](https://github.com/sequelize/sequelize/blob/ea444d318402f5de7f13f2c8dd6512fe0b8a38d8/lib/hooks.js#L372)
A hook that is run before a find (select) query, after any { include: {all: ...} } options are expanded A hook that is run before a find (select) query, after any { include: {all: ...} } options are expanded
...@@ -412,7 +428,7 @@ A hook that is run before a find (select) query, after any { include: {all: ...} ...@@ -412,7 +428,7 @@ A hook that is run before a find (select) query, after any { include: {all: ...}
<a name="beforefindafteroptions"></a> <a name="beforefindafteroptions"></a>
## `beforeFindAfterOptions(name, fn)` ## `beforeFindAfterOptions(name, fn)`
[View code](https://github.com/sequelize/sequelize/blob/0de404640d4c71e2d1f1259356650dfb586a248b/lib/hooks.js#L370) [View code](https://github.com/sequelize/sequelize/blob/ea444d318402f5de7f13f2c8dd6512fe0b8a38d8/lib/hooks.js#L379)
A hook that is run before a find (select) query, after all option parsing is complete A hook that is run before a find (select) query, after all option parsing is complete
...@@ -428,7 +444,7 @@ A hook that is run before a find (select) query, after all option parsing is com ...@@ -428,7 +444,7 @@ A hook that is run before a find (select) query, after all option parsing is com
<a name="afterfind"></a> <a name="afterfind"></a>
## `afterFind(name, fn)` ## `afterFind(name, fn)`
[View code](https://github.com/sequelize/sequelize/blob/0de404640d4c71e2d1f1259356650dfb586a248b/lib/hooks.js#L377) [View code](https://github.com/sequelize/sequelize/blob/ea444d318402f5de7f13f2c8dd6512fe0b8a38d8/lib/hooks.js#L386)
A hook that is run after a find (select) query A hook that is run after a find (select) query
...@@ -444,7 +460,7 @@ A hook that is run after a find (select) query ...@@ -444,7 +460,7 @@ A hook that is run after a find (select) query
<a name="beforedefine"></a> <a name="beforedefine"></a>
## `beforeDefine(name, fn)` ## `beforeDefine(name, fn)`
[View code](https://github.com/sequelize/sequelize/blob/0de404640d4c71e2d1f1259356650dfb586a248b/lib/hooks.js#L384) [View code](https://github.com/sequelize/sequelize/blob/ea444d318402f5de7f13f2c8dd6512fe0b8a38d8/lib/hooks.js#L393)
A hook that is run before a define call A hook that is run before a define call
...@@ -460,7 +476,7 @@ A hook that is run before a define call ...@@ -460,7 +476,7 @@ A hook that is run before a define call
<a name="afterdefine"></a> <a name="afterdefine"></a>
## `afterDefine(name, fn)` ## `afterDefine(name, fn)`
[View code](https://github.com/sequelize/sequelize/blob/0de404640d4c71e2d1f1259356650dfb586a248b/lib/hooks.js#L391) [View code](https://github.com/sequelize/sequelize/blob/ea444d318402f5de7f13f2c8dd6512fe0b8a38d8/lib/hooks.js#L400)
A hook that is run after a define call A hook that is run after a define call
...@@ -476,7 +492,7 @@ A hook that is run after a define call ...@@ -476,7 +492,7 @@ A hook that is run after a define call
<a name="beforeinit"></a> <a name="beforeinit"></a>
## `beforeInit(name, fn)` ## `beforeInit(name, fn)`
[View code](https://github.com/sequelize/sequelize/blob/0de404640d4c71e2d1f1259356650dfb586a248b/lib/hooks.js#L398) [View code](https://github.com/sequelize/sequelize/blob/ea444d318402f5de7f13f2c8dd6512fe0b8a38d8/lib/hooks.js#L407)
A hook that is run before Sequelize() call A hook that is run before Sequelize() call
...@@ -492,7 +508,7 @@ A hook that is run before Sequelize() call ...@@ -492,7 +508,7 @@ A hook that is run before Sequelize() call
<a name="afterinit"></a> <a name="afterinit"></a>
## `afterInit(name, fn)` ## `afterInit(name, fn)`
[View code](https://github.com/sequelize/sequelize/blob/0de404640d4c71e2d1f1259356650dfb586a248b/lib/hooks.js#L405) [View code](https://github.com/sequelize/sequelize/blob/ea444d318402f5de7f13f2c8dd6512fe0b8a38d8/lib/hooks.js#L414)
A hook that is run after Sequelize() call A hook that is run after Sequelize() call
...@@ -508,7 +524,7 @@ A hook that is run after Sequelize() call ...@@ -508,7 +524,7 @@ A hook that is run after Sequelize() call
<a name="beforesync"></a> <a name="beforesync"></a>
## `beforeSync(name, fn)` ## `beforeSync(name, fn)`
[View code](https://github.com/sequelize/sequelize/blob/0de404640d4c71e2d1f1259356650dfb586a248b/lib/hooks.js#L412) [View code](https://github.com/sequelize/sequelize/blob/ea444d318402f5de7f13f2c8dd6512fe0b8a38d8/lib/hooks.js#L421)
A hook that is run before Model.sync call A hook that is run before Model.sync call
...@@ -524,7 +540,7 @@ A hook that is run before Model.sync call ...@@ -524,7 +540,7 @@ A hook that is run before Model.sync call
<a name="aftersync"></a> <a name="aftersync"></a>
## `afterSync(name, fn)` ## `afterSync(name, fn)`
[View code](https://github.com/sequelize/sequelize/blob/0de404640d4c71e2d1f1259356650dfb586a248b/lib/hooks.js#L419) [View code](https://github.com/sequelize/sequelize/blob/ea444d318402f5de7f13f2c8dd6512fe0b8a38d8/lib/hooks.js#L428)
A hook that is run after Model.sync call A hook that is run after Model.sync call
...@@ -540,7 +556,7 @@ A hook that is run after Model.sync call ...@@ -540,7 +556,7 @@ A hook that is run after Model.sync call
<a name="beforebulksync"></a> <a name="beforebulksync"></a>
## `beforeBulkSync(name, fn)` ## `beforeBulkSync(name, fn)`
[View code](https://github.com/sequelize/sequelize/blob/0de404640d4c71e2d1f1259356650dfb586a248b/lib/hooks.js#L426) [View code](https://github.com/sequelize/sequelize/blob/ea444d318402f5de7f13f2c8dd6512fe0b8a38d8/lib/hooks.js#L435)
A hook that is run before sequelize.sync call A hook that is run before sequelize.sync call
...@@ -556,7 +572,7 @@ A hook that is run before sequelize.sync call ...@@ -556,7 +572,7 @@ A hook that is run before sequelize.sync call
<a name="afterbulksync"></a> <a name="afterbulksync"></a>
## `afterBulkSync` ## `afterBulkSync`
[View code](https://github.com/sequelize/sequelize/blob/0de404640d4c71e2d1f1259356650dfb586a248b/lib/hooks.js#L434) [View code](https://github.com/sequelize/sequelize/blob/ea444d318402f5de7f13f2c8dd6512fe0b8a38d8/lib/hooks.js#L443)
A hook that is run after sequelize.sync call A hook that is run after sequelize.sync call
......
...@@ -227,7 +227,8 @@ Hooks.hasHooks = Hooks.hasHook; ...@@ -227,7 +227,8 @@ Hooks.hasHooks = Hooks.hasHook;
/** /**
* A hook that is run when validation fails * A hook that is run when validation fails
* @param {String} name * @param {String} name
* @param {Function} fn A callback function that is called with instance, options, error * @param {Function} fn A callback function that is called with instance, options, error. Error is the
* SequelizeValidationError. If the callback throws an error, it will replace the original validation error.
* @name validationFailed * @name validationFailed
*/ */
......
Markdown is supported
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!