Merge branch 'alpha.4' of https://github.com/strapi/strapi into improvement/generators

This commit is contained in:
Pierre Burgy 2017-03-02 11:02:56 +01:00
commit 0322eddff1
3 changed files with 46 additions and 10 deletions

View File

@ -18,6 +18,8 @@ const utils = require('./utils/');
// Strapi helpers for models.
const utilsModels = require('strapi-utils').models;
const PIVOT_PREFIX = '_pivot_';
/**
* Bookshelf hook
*/
@ -90,7 +92,7 @@ module.exports = function (strapi) {
// Return callback if there is no model
if (_.isEmpty(models)) {
cb();
// Break the loop.
return false;
}
@ -124,6 +126,27 @@ module.exports = function (strapi) {
idAttribute: _.get(definition, 'options.idAttribute') || 'id'
};
if (_.isString(_.get(connection, 'options.pivot_prefix'))) {
loadedModel.toJSON = function(options = {}) {
const { shallow = false, omitPivot = false } = options;
const attributes = this.serialize(options);
if (!shallow) {
const pivot = this.pivot && !omitPivot && this.pivot.attributes;
// Remove pivot attributes with prefix.
_.keys(pivot).forEach(key => delete attributes[`${PIVOT_PREFIX}${key}`]);
// Add pivot attributes without prefix.
const pivotAttributes = _.mapKeys(pivot, (value, key) => `${connection.options.pivot_prefix}${key}`);
return Object.assign({}, attributes, pivotAttributes);
}
return attributes;
};
}
// Initialize the global variable with the
// capitalized model name.
global[globalName] = {};
@ -248,6 +271,10 @@ module.exports = function (strapi) {
}
loadedModel[name] = function () {
if (_.isArray(_.get(details, 'withPivot')) && !_.isEmpty(details.withPivot)) {
return this.belongsToMany(global[_.upperFirst(details.collection)], tableName, relationship.attribute + '_' + relationship.column, details.attribute + '_' + details.column).withPivot(details.withPivot);
}
return this.belongsToMany(global[_.upperFirst(details.collection)], tableName, relationship.attribute + '_' + relationship.column, details.attribute + '_' + details.column);
};
break;

View File

@ -15,7 +15,7 @@ const Redis = require('ioredis');
* Redis hook
*/
module.exports = function () {
module.exports = function (strapi) {
const hook = {
/**
@ -26,7 +26,8 @@ module.exports = function () {
port: 6379,
host: 'localhost',
family: 4,
db: 0
db: 0,
showFriendlyErrorStack: (process.env.NODE_ENV !== 'production')
},
/**
@ -49,9 +50,9 @@ module.exports = function () {
const redis = new Redis(connection.settings);
redis.on('error', (err) => {
cb(err);
return process.kill();
strapi.log.error(err);
process.exit(0);
return;
});
// Utils function.
@ -93,7 +94,9 @@ module.exports = function () {
});
}
done();
redis.on('ready', () => {
done();
});
} catch (e) {
cb(e);

View File

@ -43,7 +43,7 @@ module.exports = function () {
watch: true,
watchDirectory: process.cwd(),
watchIgnoreDotFiles: true, // Whether to ignore file starting with a '.'
watchIgnorePatterns: ['node_modules/**/*', 'public/**/*'], // Ignore patterns to use when watching files.
watchIgnorePatterns: ['node_modules/**/*', 'public/**/*', '.git/**/*', '.idea'], // Ignore patterns to use when watching files.
killTree: true, // Kills the entire child process tree on `exit`,
spinSleepTime: 0,
command: 'node --harmony-async-await'
@ -52,9 +52,15 @@ module.exports = function () {
const child = new (forever.Monitor)('server.js', options);
// Run listeners
child.on('restart', () => {
child.on('watch:restart', (info) => {
logger.verbose('Restarting due to ' + info.file + '... (' + info.stat.replace(child.cwd, '.') + ')');
console.log();
logger.info('Restarting due to changes...');
});
child.on('exit:code', function(code) {
if (code) {
process.exit(code);
}
});
// Start child process