From 90dcf5ae5bbdf86a649e8df1934b31fa09d691c1 Mon Sep 17 00:00:00 2001 From: Derrick Mehaffy Date: Wed, 7 Aug 2019 02:34:03 -0700 Subject: [PATCH 1/2] Adding code from Alex and bookshelf-uuid package --- packages/strapi-hook-bookshelf/lib/mount-models.js | 3 +++ packages/strapi-hook-bookshelf/package.json | 1 + 2 files changed, 4 insertions(+) diff --git a/packages/strapi-hook-bookshelf/lib/mount-models.js b/packages/strapi-hook-bookshelf/lib/mount-models.js index 1f6bba0797..11bea5bc70 100644 --- a/packages/strapi-hook-bookshelf/lib/mount-models.js +++ b/packages/strapi-hook-bookshelf/lib/mount-models.js @@ -692,6 +692,9 @@ module.exports = ({ models, target, plugin = false }, ctx) => { // Initialize lifecycle callbacks. loadedModel.initialize = function() { + // Load bookshelf plugin arguments from model options + this.constructor.__super__.initialize.apply(this, arguments); + const lifecycle = { creating: 'beforeCreate', created: 'afterCreate', diff --git a/packages/strapi-hook-bookshelf/package.json b/packages/strapi-hook-bookshelf/package.json index 8b197c6647..3967dfe251 100644 --- a/packages/strapi-hook-bookshelf/package.json +++ b/packages/strapi-hook-bookshelf/package.json @@ -17,6 +17,7 @@ "main": "./lib", "dependencies": { "bookshelf": "^0.15.1", + "bookshelf-uuid": "^1.0.1", "date-fns": "^1.30.1", "inquirer": "^6.3.1", "lodash": "^4.17.11", From 2b5a968f41f1d414210ad72ac4445bda9017992d Mon Sep 17 00:00:00 2001 From: Derrick Mehaffy Date: Wed, 7 Aug 2019 02:56:53 -0700 Subject: [PATCH 2/2] remove bookshelf-uuid from hook-bookshelf and add docs --- docs/3.0.0-beta.x/configurations/configurations.md | 12 ++++++++++++ docs/3.0.0-beta.x/guides/models.md | 1 + packages/strapi-hook-bookshelf/package.json | 1 - 3 files changed, 13 insertions(+), 1 deletion(-) diff --git a/docs/3.0.0-beta.x/configurations/configurations.md b/docs/3.0.0-beta.x/configurations/configurations.md index e0c62c8e82..3a614b05d4 100644 --- a/docs/3.0.0-beta.x/configurations/configurations.md +++ b/docs/3.0.0-beta.x/configurations/configurations.md @@ -147,6 +147,18 @@ module.exports = (mongoose, connection) => { }; ``` +Another example would be using the `bookshelf-uuid` plugin for MySQL, you can register it like this: + +**Path —** `./config/functions/bookshelf.js`. + +```js +'use strict'; + +module.exports = (bookshelf, connection) => { + bookshelf.plugin(require('bookshelf-uuid')); +}; +``` + --- ## Locales diff --git a/docs/3.0.0-beta.x/guides/models.md b/docs/3.0.0-beta.x/guides/models.md index afd04f3a31..74fadf6113 100644 --- a/docs/3.0.0-beta.x/guides/models.md +++ b/docs/3.0.0-beta.x/guides/models.md @@ -34,6 +34,7 @@ The options key on the model-json states. - `idAttribute`: This tells the model which attribute to expect as the unique identifier for each database row (typically an auto-incrementing primary key named 'id'). _Only valid for strapi-hook-bookshelf_ - `idAttributeType`: Data type of `idAttribute`, accepted list of value below. _Only valid for strapi-hook-bookshelf_ - `timestamps`: This tells the model which attributes to use for timestamps. Accepts either `boolean` or `Array` of strings where first element is create data and second element is update date. Default value when set to `true` for Bookshelf is `["created_at", "updated_at"]` and for MongoDB is `["createdAt", "updatedAt"]`. +- `uuid` : Boolean to enable UUID support on MySQL, you will need to set the `idAttributeType` to `uuid` as well and install the `bookshelf-uuid` package. To load the package you can see [this example](../configurations/configurations.md#bookshelf-mongoose). ## Define the attributes diff --git a/packages/strapi-hook-bookshelf/package.json b/packages/strapi-hook-bookshelf/package.json index 3967dfe251..8b197c6647 100644 --- a/packages/strapi-hook-bookshelf/package.json +++ b/packages/strapi-hook-bookshelf/package.json @@ -17,7 +17,6 @@ "main": "./lib", "dependencies": { "bookshelf": "^0.15.1", - "bookshelf-uuid": "^1.0.1", "date-fns": "^1.30.1", "inquirer": "^6.3.1", "lodash": "^4.17.11",