From ca46db9b313495ab4ce8a446d4202eca918aefdd Mon Sep 17 00:00:00 2001 From: Jim LAURIE Date: Tue, 30 Apr 2019 18:33:14 +0200 Subject: [PATCH] Fix #3192 filter on timestamp attributes --- packages/strapi-hook-bookshelf/lib/index.js | 3 +++ packages/strapi-hook-mongoose/lib/index.js | 3 +++ packages/strapi-utils/lib/buildQuery.js | 2 +- 3 files changed, 7 insertions(+), 1 deletion(-) diff --git a/packages/strapi-hook-bookshelf/lib/index.js b/packages/strapi-hook-bookshelf/lib/index.js index e4692fdcb2..27a57d79d8 100644 --- a/packages/strapi-hook-bookshelf/lib/index.js +++ b/packages/strapi-hook-bookshelf/lib/index.js @@ -834,6 +834,9 @@ module.exports = function(strapi) { }; } + // Save all attributes (with timestamps) + target[model].allAttributes = _.clone(definition.attributes); + // Equilize tables if (connection.options && connection.options.autoMigration !== false) { await handler(loadedModel.tableName, definition.attributes); diff --git a/packages/strapi-hook-mongoose/lib/index.js b/packages/strapi-hook-mongoose/lib/index.js index a2f14c427e..541fae1ead 100644 --- a/packages/strapi-hook-mongoose/lib/index.js +++ b/packages/strapi-hook-mongoose/lib/index.js @@ -303,6 +303,9 @@ module.exports = function(strapi) { _.get(definition, 'options.minimize', false) === true ); + // Save all attributes (with timestamps) + target[model].allAttributes = _.clone(definition.attributes); + collection.schema.options.toObject = collection.schema.options.toJSON = { virtuals: true, transform: function(doc, returned, opts) { diff --git a/packages/strapi-utils/lib/buildQuery.js b/packages/strapi-utils/lib/buildQuery.js index c10374e946..b66b43b55d 100644 --- a/packages/strapi-utils/lib/buildQuery.js +++ b/packages/strapi-utils/lib/buildQuery.js @@ -5,7 +5,7 @@ const findModelByAssoc = assoc => { return models[assoc.collection || assoc.model]; }; -const isAttribute = (model, field) => _.has(model.attributes, field) || model.primaryKey === field; +const isAttribute = (model, field) => _.has(model.allAttributes, field) || model.primaryKey === field; /** * Returns the model, attribute name and association from a path of relation