Handle default values with Bookshelf

This commit is contained in:
Aurelsicoko 2018-04-06 17:49:08 +02:00
parent cc6db73e33
commit 057d62b9f9
3 changed files with 11 additions and 4 deletions

View File

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

View File

@ -55,4 +55,4 @@
"npm": ">= 5.3.0"
},
"license": "MIT"
}
}

View File

@ -46,4 +46,4 @@
"npm": ">= 5.0.0"
},
"license": "MIT"
}
}