From 057d62b9f967c02d4ce549c40f2d46443eff01bf Mon Sep 17 00:00:00 2001 From: Aurelsicoko Date: Fri, 6 Apr 2018 17:49:08 +0200 Subject: [PATCH] Handle default values with Bookshelf --- packages/strapi-bookshelf/lib/index.js | 11 +++++++++-- packages/strapi-bookshelf/package.json | 2 +- packages/strapi-knex/package.json | 2 +- 3 files changed, 11 insertions(+), 4 deletions(-) diff --git a/packages/strapi-bookshelf/lib/index.js b/packages/strapi-bookshelf/lib/index.js index 99c8d984c0..72e76213be 100755 --- a/packages/strapi-bookshelf/lib/index.js +++ b/packages/strapi-bookshelf/lib/index.js @@ -89,9 +89,16 @@ module.exports = function(strapi) { tableName: definition.collectionName, hasTimestamps: _.get(definition, 'options.timestamps') === true, idAttribute: _.get(definition, 'options.idAttribute', 'id'), - associations: [] - }, definition.options); + associations: [], + defaults: Object.keys(definition.attributes).reduce((acc, current) => { + if (definition.attributes[current].type && definition.attributes[current].default) { + acc[current] = definition.attributes[current].default; + } + return acc; + }, {}) + }, definition.options); + if (_.isString(_.get(connection, 'options.pivot_prefix'))) { loadedModel.toJSON = function(options = {}) { const { shallow = false, omitPivot = false } = options; diff --git a/packages/strapi-bookshelf/package.json b/packages/strapi-bookshelf/package.json index 055b12c625..cd4b1b9473 100755 --- a/packages/strapi-bookshelf/package.json +++ b/packages/strapi-bookshelf/package.json @@ -55,4 +55,4 @@ "npm": ">= 5.3.0" }, "license": "MIT" -} \ No newline at end of file +} diff --git a/packages/strapi-knex/package.json b/packages/strapi-knex/package.json index be44035ed6..c650cd122f 100755 --- a/packages/strapi-knex/package.json +++ b/packages/strapi-knex/package.json @@ -46,4 +46,4 @@ "npm": ">= 5.0.0" }, "license": "MIT" -} \ No newline at end of file +}