mirror of
https://github.com/strapi/strapi.git
synced 2025-12-26 22:54:31 +00:00
Ability to use custom timestamps.
This commit is contained in:
parent
e4dc27be54
commit
b04ba69370
@ -89,7 +89,7 @@ module.exports = function(strapi) {
|
||||
// Register the final model for Bookshelf.
|
||||
const loadedModel = _.assign({
|
||||
tableName: definition.collectionName,
|
||||
hasTimestamps: _.get(definition, 'options.timestamps') === true,
|
||||
hasTimestamps: _.get(definition, 'options.timestamps'),
|
||||
idAttribute: _.get(definition, 'options.idAttribute', 'id'),
|
||||
associations: [],
|
||||
defaults: Object.keys(definition.attributes).reduce((acc, current) => {
|
||||
@ -619,10 +619,10 @@ module.exports = function(strapi) {
|
||||
|
||||
// Add created_at and updated_at field if timestamp option is true
|
||||
if (loadedModel.hasTimestamps) {
|
||||
definition.attributes['created_at'] = {
|
||||
definition.attributes[loadedModel.hasTimestamps[0]] = {
|
||||
type: 'timestamp'
|
||||
};
|
||||
definition.attributes['updated_at'] = {
|
||||
definition.attributes[loadedModel.hasTimestamps[1]] = {
|
||||
type: 'timestampUpdate'
|
||||
};
|
||||
}
|
||||
@ -701,8 +701,8 @@ module.exports = function(strapi) {
|
||||
|
||||
// Remove from attributes (auto handled by bookshlef and not displayed on ctb)
|
||||
if (loadedModel.hasTimestamps) {
|
||||
delete definition.attributes['created_at'];
|
||||
delete definition.attributes['updated_at'];
|
||||
delete definition.attributes[loadedModel.hasTimestamps[0]];
|
||||
delete definition.attributes[loadedModel.hasTimestamps[1]];
|
||||
}
|
||||
|
||||
resolve();
|
||||
|
||||
@ -207,7 +207,10 @@ module.exports = function (strapi) {
|
||||
});
|
||||
});
|
||||
|
||||
collection.schema.set('timestamps', _.get(definition, 'options.timestamps') === true);
|
||||
let timestamps = {};
|
||||
_.set(timestamps.createdAt, _.get(definition, 'options.timestamps[0]'));
|
||||
_.set(timestamps.updatedAt, _.get(definition, 'options.timestamps[1]'));
|
||||
collection.schema.set('timestamps', timestamps);
|
||||
collection.schema.set('minimize', _.get(definition, 'options.minimize', false) === true);
|
||||
|
||||
collection.schema.options.toObject = collection.schema.options.toJSON = {
|
||||
|
||||
@ -77,15 +77,10 @@ export function* submit() {
|
||||
let shouldAddTranslationSuffix = false;
|
||||
|
||||
// Remove the updated_at & created_at fields so it is updated correctly when using Postgres or MySQL db
|
||||
if (record.updated_at) {
|
||||
delete record.created_at;
|
||||
delete record.updated_at;
|
||||
}
|
||||
|
||||
// Remove the updatedAt & createdAt fields so it is updated correctly when using MongoDB
|
||||
if (record.updatedAt) {
|
||||
delete record.createdAt;
|
||||
delete record.updatedAt;
|
||||
const timestamps = get(schema, ['models', currentModelName, 'options', 'timestamps'], null);
|
||||
if (timestamps) {
|
||||
delete record[timestamps[0]];
|
||||
delete record[timestamps[1]];
|
||||
}
|
||||
|
||||
try {
|
||||
|
||||
@ -17,6 +17,7 @@ const pickData = (model) => _.pick(model, [
|
||||
'globalId',
|
||||
'globalName',
|
||||
'orm',
|
||||
'options.timestamps',
|
||||
'loadedModel',
|
||||
'primaryKey',
|
||||
'associations'
|
||||
@ -330,8 +331,9 @@ module.exports = async cb => {
|
||||
// Here we just need to add the data from the current schema Object
|
||||
apisToAdd.map(apiPath => {
|
||||
const api = _.get(schema.models, apiPath);
|
||||
const { search, filters, bulkActions, pageEntries } = _.get(prevSchema, 'generalSettings');
|
||||
const { search, filters, bulkActions, pageEntries, options } = _.get(prevSchema, 'generalSettings');
|
||||
|
||||
_.set(api, 'options', options);
|
||||
_.set(api, 'filters', filters);
|
||||
_.set(api, 'search', search);
|
||||
_.set(api, 'bulkActions', bulkActions);
|
||||
|
||||
Loading…
x
Reference in New Issue
Block a user