From 2d108af07284a7ae23481411081a067715b17dcd Mon Sep 17 00:00:00 2001 From: Prateek Narula Date: Mon, 11 Mar 2019 18:41:12 +0100 Subject: [PATCH 1/4] update needed eithh document of code --- docs/3.x.x/guides/models.md | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/docs/3.x.x/guides/models.md b/docs/3.x.x/guides/models.md index df28f7ddec..1f5389b293 100644 --- a/docs/3.x.x/guides/models.md +++ b/docs/3.x.x/guides/models.md @@ -682,8 +682,8 @@ Callbacks on `fetch`: - afterFetch Callbacks on `fetchAll`: - - beforeFetchAll - - afterFetchAll + - beforeFetchCollection + - afterFetchCollection Callbacks on `create`: - beforeCreate From 5821b8ac1515f019e3a6bcf91f59b18511151276 Mon Sep 17 00:00:00 2001 From: Prateek Narula Date: Tue, 12 Mar 2019 17:23:38 +0100 Subject: [PATCH 2/4] FetchCollection changed to FetchAll beforeFetchCollection will be beforeFetchAll and afterFetchCollection will be afterFetchAll. Lifecycle hook variables need to be changed to be inline with mongoose. See https://github.com/strapi/strapi/blob/master/packages/strapi-hook-mongoose/lib/index.js --- packages/strapi-hook-bookshelf/lib/index.js | 10 +++++----- 1 file changed, 5 insertions(+), 5 deletions(-) diff --git a/packages/strapi-hook-bookshelf/lib/index.js b/packages/strapi-hook-bookshelf/lib/index.js index 2505c0541b..332c03979d 100644 --- a/packages/strapi-hook-bookshelf/lib/index.js +++ b/packages/strapi-hook-bookshelf/lib/index.js @@ -236,9 +236,9 @@ module.exports = function(strapi) { updating: 'beforeUpdate', updated: 'afterUpdate', fetching: 'beforeFetch', - 'fetching:collection': 'beforeFetchCollection', + 'fetching:collection': 'beforeFetchAll', fetched: 'afterFetch', - 'fetched:collection': 'afterFetchCollection', + 'fetched:collection': 'afterFetchAll', saving: 'beforeSave', saved: 'afterSave' }; @@ -287,9 +287,9 @@ module.exports = function(strapi) { } return _.isFunction( - target[model.toLowerCase()]['beforeFetchCollection'] + target[model.toLowerCase()]['beforeFetchAll'] ) - ? target[model.toLowerCase()]['beforeFetchCollection'] + ? target[model.toLowerCase()]['beforeFetchAll'] : Promise.resolve(); }); @@ -314,7 +314,7 @@ module.exports = function(strapi) { target: 'afterFetch' }, { name: 'fetched:collection', - target: 'afterFetchCollection' + target: 'afterFetchAll' }]; const jsonFormatter = (attributes) => { From c0688b6ace96eca5a1052fd925e237cce1a86fcd Mon Sep 17 00:00:00 2001 From: Prateek Narula Date: Tue, 12 Mar 2019 17:26:51 +0100 Subject: [PATCH 3/4] Corresponding to change in strapi-hook-bookshelf afterFetchAll and beforeFetchAll hook definition added --- .../templates/bookshelf/model.template | 8 ++++++++ 1 file changed, 8 insertions(+) diff --git a/packages/strapi-generate-api/templates/bookshelf/model.template b/packages/strapi-generate-api/templates/bookshelf/model.template index 6a197959cd..6a75629d9e 100644 --- a/packages/strapi-generate-api/templates/bookshelf/model.template +++ b/packages/strapi-generate-api/templates/bookshelf/model.template @@ -20,6 +20,14 @@ module.exports = { // After fetching a value. // Fired after a `fetch` operation. // afterFetch: async (model, response, options) => {}, + + // Before fetching all values. + // Fired before a `fetchAll` operation. + // beforeFetchAll: async (model, columns, options) => {}, + + // After fetching all values. + // Fired after a `fetchAll` operation. + // afterFetchAll: async (model, response, options) => {}, // Before creating a value. // Fired before an `insert` query. From 62bc8e2287903c940ca14e043cfb6524e9c23519 Mon Sep 17 00:00:00 2001 From: Prateek Narula Date: Tue, 12 Mar 2019 17:31:06 +0100 Subject: [PATCH 4/4] reverted To be inline with mongoose code --- docs/3.x.x/guides/models.md | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/docs/3.x.x/guides/models.md b/docs/3.x.x/guides/models.md index 1f5389b293..df28f7ddec 100644 --- a/docs/3.x.x/guides/models.md +++ b/docs/3.x.x/guides/models.md @@ -682,8 +682,8 @@ Callbacks on `fetch`: - afterFetch Callbacks on `fetchAll`: - - beforeFetchCollection - - afterFetchCollection + - beforeFetchAll + - afterFetchAll Callbacks on `create`: - beforeCreate