Removed explicit loading of Bookshelf registry plugin

- as per 5a5a5d162e, the Bookshelf registry plugin is now in core
- we no longer need to explicitly load the plugin, and it displays a
  warning if you do
- this change also turns `._models` into `.registry.models`, so our code has
  been updated to reflect that
This commit is contained in:
Daniel Lockyer 2021-08-25 12:39:54 +02:00
parent 7a3725fdbf
commit 80fa1d903e
3 changed files with 11 additions and 14 deletions

View File

@ -3,7 +3,7 @@ const ghostBookshelf = require('./base');
const candidates = [];
_.each(ghostBookshelf._models, (model) => {
_.each(ghostBookshelf.registry.models, (model) => {
candidates.push([model, model.prototype.tableName.replace(/s$/, '')]);
});

View File

@ -10,9 +10,6 @@ const db = require('../../data/db');
// Initializes a new Bookshelf instance called ghostBookshelf, for reference elsewhere in Ghost.
const ghostBookshelf = bookshelf(db.knex);
// Load the Bookshelf registry plugin, which helps us avoid circular dependencies
ghostBookshelf.plugin('registry');
ghostBookshelf.plugin(plugins.eagerLoad);
// Add committed/rollback events.

View File

@ -106,17 +106,17 @@ module.exports = function (Bookshelf) {
if (!withRelated) {
return _.map(objects, (object) => {
object = Bookshelf._models[modelName].prototype.toJSON.bind({
object = Bookshelf.registry.models[modelName].prototype.toJSON.bind({
attributes: object,
related: function (key) {
return object[key];
},
serialize: Bookshelf._models[modelName].prototype.serialize,
formatsToJSON: Bookshelf._models[modelName].prototype.formatsToJSON
serialize: Bookshelf.registry.models[modelName].prototype.serialize,
formatsToJSON: Bookshelf.registry.models[modelName].prototype.formatsToJSON
})();
object = Bookshelf._models[modelName].prototype.fixBools(object);
object = Bookshelf._models[modelName].prototype.fixDatesWhenFetch(object);
object = Bookshelf.registry.models[modelName].prototype.fixBools(object);
object = Bookshelf.registry.models[modelName].prototype.fixDatesWhenFetch(object);
return object;
});
}
@ -180,7 +180,7 @@ module.exports = function (Bookshelf) {
object[relation] = relationsToAttach[relation][object.id];
});
object = Bookshelf._models[modelName].prototype.toJSON.bind({
object = Bookshelf.registry.models[modelName].prototype.toJSON.bind({
attributes: object,
_originalOptions: {
withRelated: Object.keys(relationsToAttach)
@ -188,12 +188,12 @@ module.exports = function (Bookshelf) {
related: function (key) {
return object[key];
},
serialize: Bookshelf._models[modelName].prototype.serialize,
formatsToJSON: Bookshelf._models[modelName].prototype.formatsToJSON
serialize: Bookshelf.registry.models[modelName].prototype.serialize,
formatsToJSON: Bookshelf.registry.models[modelName].prototype.formatsToJSON
})();
object = Bookshelf._models[modelName].prototype.fixBools(object);
object = Bookshelf._models[modelName].prototype.fixDatesWhenFetch(object);
object = Bookshelf.registry.models[modelName].prototype.fixBools(object);
object = Bookshelf.registry.models[modelName].prototype.fixDatesWhenFetch(object);
return object;
});