mirror of
https://github.com/TryGhost/Ghost.git
synced 2025-01-01 23:37:43 +03:00
Extracted Bookshelf filtered collection code into plugin
no issue - this commit extracts all code relating to filtering collections to a separate plugin to break down the Base model
This commit is contained in:
parent
930df4b7fb
commit
89ba4081b4
@ -54,7 +54,9 @@ ghostBookshelf.plugin(require('./sanitize'));
|
||||
|
||||
ghostBookshelf.plugin(require('./generate-slug'));
|
||||
|
||||
ghostBookshelf.plugin(require('./plugins/bulk-operations'));
|
||||
ghostBookshelf.plugin(require('./bulk-operations'));
|
||||
|
||||
ghostBookshelf.plugin(require('./filtered-collection'));
|
||||
|
||||
// Manages nested updates (relationships)
|
||||
ghostBookshelf.plugin('bookshelf-relations', {
|
||||
|
35
core/server/models/base/filtered-collection.js
Normal file
35
core/server/models/base/filtered-collection.js
Normal file
@ -0,0 +1,35 @@
|
||||
/**
|
||||
* @param {import('bookshelf')} Bookshelf
|
||||
*/
|
||||
module.exports = function (Bookshelf) {
|
||||
Bookshelf.Model = Bookshelf.Model.extend({}, {
|
||||
getFilteredCollection: function getFilteredCollection(options) {
|
||||
const filteredCollection = this.forge();
|
||||
|
||||
// Apply model-specific query behaviour
|
||||
filteredCollection.applyCustomQuery(options);
|
||||
|
||||
// Add Filter behaviour
|
||||
filteredCollection.applyDefaultAndCustomFilters(options);
|
||||
|
||||
// Apply model-specific search behaviour
|
||||
filteredCollection.applySearchQuery(options);
|
||||
|
||||
return filteredCollection;
|
||||
},
|
||||
|
||||
getFilteredCollectionQuery: function getFilteredCollectionQuery(options) {
|
||||
const filteredCollection = this.getFilteredCollection(options);
|
||||
const filteredCollectionQuery = filteredCollection.query();
|
||||
|
||||
if (options.transacting) {
|
||||
filteredCollectionQuery.transacting(options.transacting);
|
||||
if (options.forUpdate) {
|
||||
filteredCollectionQuery.forUpdate();
|
||||
}
|
||||
}
|
||||
|
||||
return filteredCollectionQuery;
|
||||
}
|
||||
});
|
||||
};
|
@ -327,37 +327,6 @@ ghostBookshelf.Model = ghostBookshelf.Model.extend({
|
||||
|
||||
isExternalUser: function isExternalUser(id) {
|
||||
return id === ghostBookshelf.Model.externalUser || id === ghostBookshelf.Model.externalUser.toString();
|
||||
},
|
||||
|
||||
// ## Model Data Functions
|
||||
|
||||
getFilteredCollection: function getFilteredCollection(options) {
|
||||
const filteredCollection = this.forge();
|
||||
|
||||
// Apply model-specific query behaviour
|
||||
filteredCollection.applyCustomQuery(options);
|
||||
|
||||
// Add Filter behaviour
|
||||
filteredCollection.applyDefaultAndCustomFilters(options);
|
||||
|
||||
// Apply model-specific search behaviour
|
||||
filteredCollection.applySearchQuery(options);
|
||||
|
||||
return filteredCollection;
|
||||
},
|
||||
|
||||
getFilteredCollectionQuery: function getFilteredCollectionQuery(options) {
|
||||
const filteredCollection = this.getFilteredCollection(options);
|
||||
const filteredCollectionQuery = filteredCollection.query();
|
||||
|
||||
if (options.transacting) {
|
||||
filteredCollectionQuery.transacting(options.transacting);
|
||||
if (options.forUpdate) {
|
||||
filteredCollectionQuery.forUpdate();
|
||||
}
|
||||
}
|
||||
|
||||
return filteredCollectionQuery;
|
||||
}
|
||||
});
|
||||
|
||||
|
Loading…
Reference in New Issue
Block a user