mirror of
https://github.com/strapi/strapi.git
synced 2025-11-09 22:59:14 +00:00
Handle default values with Bookshelf
This commit is contained in:
parent
cc6db73e33
commit
057d62b9f9
@ -89,9 +89,16 @@ module.exports = function(strapi) {
|
|||||||
tableName: definition.collectionName,
|
tableName: definition.collectionName,
|
||||||
hasTimestamps: _.get(definition, 'options.timestamps') === true,
|
hasTimestamps: _.get(definition, 'options.timestamps') === true,
|
||||||
idAttribute: _.get(definition, 'options.idAttribute', 'id'),
|
idAttribute: _.get(definition, 'options.idAttribute', 'id'),
|
||||||
associations: []
|
associations: [],
|
||||||
}, definition.options);
|
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'))) {
|
if (_.isString(_.get(connection, 'options.pivot_prefix'))) {
|
||||||
loadedModel.toJSON = function(options = {}) {
|
loadedModel.toJSON = function(options = {}) {
|
||||||
const { shallow = false, omitPivot = false } = options;
|
const { shallow = false, omitPivot = false } = options;
|
||||||
|
|||||||
@ -55,4 +55,4 @@
|
|||||||
"npm": ">= 5.3.0"
|
"npm": ">= 5.3.0"
|
||||||
},
|
},
|
||||||
"license": "MIT"
|
"license": "MIT"
|
||||||
}
|
}
|
||||||
|
|||||||
@ -46,4 +46,4 @@
|
|||||||
"npm": ">= 5.0.0"
|
"npm": ">= 5.0.0"
|
||||||
},
|
},
|
||||||
"license": "MIT"
|
"license": "MIT"
|
||||||
}
|
}
|
||||||
|
|||||||
Loading…
x
Reference in New Issue
Block a user