Merge pull request #3744 from strapi/feature/mysqlUUID

Add support for bookshelf plugin loading
This commit is contained in:
Alexandre BODIN 2019-08-07 13:44:31 +02:00 committed by GitHub
commit 3b32b78d78
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
3 changed files with 16 additions and 0 deletions

View File

@ -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

View File

@ -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

View File

@ -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',