Fix get timestamp in the admin

This commit is contained in:
Jim LAURIE 2019-01-23 15:19:34 +01:00
parent 89984e46b0
commit 0238257eec
3 changed files with 19 additions and 9 deletions

View File

@ -86,6 +86,16 @@ module.exports = function(strapi) {
primaryKey: 'id', primaryKey: 'id',
primaryKeyType: _.get(definition, 'options.idAttributeType', 'integer') primaryKeyType: _.get(definition, 'options.idAttributeType', 'integer')
}); });
// Use default timestamp column names if value is `true`
if (_.get(definition, 'options.timestamps', false) === true) {
_.set(definition, 'options.timestamps', ['created_at', 'updated_at']);
}
// Use false for values other than `Boolean` or `Array`
if (!_.isArray(_.get(definition, 'options.timestamps')) && !_.isBoolean(_.get(definition, 'options.timestamps'))) {
_.set(definition, 'options.timestamps', false);
}
// Register the final model for Bookshelf. // Register the final model for Bookshelf.
const loadedModel = _.assign({ const loadedModel = _.assign({
tableName: definition.collectionName, tableName: definition.collectionName,
@ -100,14 +110,7 @@ module.exports = function(strapi) {
return acc; return acc;
}, {}) }, {})
}, definition.options); }, definition.options);
// Use default timestamp column names if value is `true`
if (_.get(loadedModel, 'hasTimestamps') === true) {
_.set(loadedModel, 'hasTimestamps', ['created_at', 'updated_at']);
}
// Use false for values other than `Boolean` or `Array`
if (!_.isArray(_.get(loadedModel, 'hasTimestamps')) && !_.isBoolean(_.get(loadedModel, 'hasTimestamps'))) {
_.set(loadedModel, 'hasTimestamps', false);
}
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;

View File

@ -216,6 +216,7 @@ module.exports = function (strapi) {
collection.schema.set('timestamps', timestamps); collection.schema.set('timestamps', timestamps);
} else { } else {
collection.schema.set('timestamps', _.get(definition, 'options.timestamps') === true); collection.schema.set('timestamps', _.get(definition, 'options.timestamps') === true);
_.set(definition, 'options.timestamps', _.get(definition, 'options.timestamps') === true ? ['createdAt', 'updatedAt'] : false);
} }
collection.schema.set('minimize', _.get(definition, 'options.minimize', false) === true); collection.schema.set('minimize', _.get(definition, 'options.minimize', false) === true);

View File

@ -17,7 +17,7 @@ const pickData = (model) => _.pick(model, [
'globalId', 'globalId',
'globalName', 'globalName',
'orm', 'orm',
'options.timestamps', 'options',
'loadedModel', 'loadedModel',
'primaryKey', 'primaryKey',
'associations' 'associations'
@ -383,6 +383,12 @@ module.exports = async cb => {
_.set(prevSchema.models, fieldsPath, currentFields); _.set(prevSchema.models, fieldsPath, currentFields);
}); });
schemaApis.map((model) => {
const isPlugin = model.includes('plugins.');
_.set(prevSchema.models[model], 'info', _.get(!isPlugin ? strapi.models[model] : strapi[model], 'info'));
_.set(prevSchema.models[model], 'options', _.get(!isPlugin ? strapi.models[model] : strapi[model], 'options'));
});
await pluginStore.set({ key: 'schema', value: prevSchema }); await pluginStore.set({ key: 'schema', value: prevSchema });
} catch(err) { } catch(err) {