mirror of
https://github.com/strapi/strapi.git
synced 2025-12-26 06:35:47 +00:00
Load db hook if plugin model exist
This commit is contained in:
parent
45da41ce11
commit
24e4dd9bbc
@ -16,7 +16,7 @@ const utils = require('./utils/');
|
||||
const { models: utilsModels, logger } = require('strapi-utils');
|
||||
|
||||
/**
|
||||
* Bookshelf hook
|
||||
* Mongoose hook
|
||||
*/
|
||||
|
||||
module.exports = function (strapi) {
|
||||
@ -40,11 +40,6 @@ module.exports = function (strapi) {
|
||||
initialize: cb => {
|
||||
let globalName;
|
||||
|
||||
// Return callback if there is no model
|
||||
if (_.isEmpty(strapi.models) || !_.pickBy(strapi.config.connections, {connector: 'strapi-mongoose'})) {
|
||||
return cb();
|
||||
}
|
||||
|
||||
_.forEach(_.pickBy(strapi.config.connections, {connector: 'strapi-mongoose'}), (connection, connectionName) => {
|
||||
const instance = new Mongoose();
|
||||
const {host, port, username, password, database} = _.defaults(connection.settings, strapi.config.hook.settings.mongoose);
|
||||
@ -74,11 +69,6 @@ module.exports = function (strapi) {
|
||||
// Select models concerned by this connection
|
||||
const models = _.pickBy(strapi.models, { connection: connectionName });
|
||||
|
||||
// Return callback if there is no model
|
||||
if (_.isEmpty(models)) {
|
||||
return cb();
|
||||
}
|
||||
|
||||
const mountModels = (models, target, plugin = false) => {
|
||||
if (!target) return;
|
||||
|
||||
|
||||
@ -4,7 +4,7 @@
|
||||
const path = require('path');
|
||||
const glob = require('glob');
|
||||
const utils = require('../utils');
|
||||
const {merge, setWith, get, upperFirst, isString, isEmpty, isObject, pullAll, defaults, isPlainObject, forEach } = require('lodash');
|
||||
const {merge, setWith, get, upperFirst, isString, isEmpty, isObject, pullAll, defaults, isPlainObject, forEach, assign} = require('lodash');
|
||||
|
||||
module.exports.nested = function() {
|
||||
return Promise.all([
|
||||
@ -288,9 +288,9 @@ const enableHookNestedDependencies = function (name, flattenHooksConfig, force =
|
||||
// Couldn't find configurations for this hook.
|
||||
if (isEmpty(get(flattenHooksConfig, name, true))) {
|
||||
// Check if database connector is used
|
||||
const modelsUsed = Object.keys(this.api || {})
|
||||
.filter(x => isObject(this.api[x].models)) // Filter API with models
|
||||
.map(x => this.api[x].models) // Keep models
|
||||
const modelsUsed = Object.keys(assign(this.api || {}, this.plugins || {}))
|
||||
.filter(x => isObject(get(this.api, [x, 'models']) || get(this.plugins, [x, 'models']))) // Filter API with models
|
||||
.map(x => get(this.api, [x, 'models']) || get(this.plugins, [x, 'models'])) // Keep models
|
||||
.filter(models => {
|
||||
const apiModelsUsed = Object.keys(models).filter(model => {
|
||||
const connector = get(this.config.connections, models[model].connection, {}).connector;
|
||||
|
||||
Loading…
x
Reference in New Issue
Block a user