Allow custom tableName on M2M associations and select PG schema

This commit is contained in:
Aurélien Georget 2017-01-23 16:28:20 +01:00
parent 206d673822
commit 9aa2cedf85
2 changed files with 20 additions and 4 deletions

View File

@ -192,7 +192,7 @@ module.exports = function (strapi) {
break; break;
} }
case 'belongsToMany': { case 'belongsToMany': {
const tableName = _.map(_.sortBy([strapi.models[details.collection].attributes[details.via], details], 'collection'), table => { const tableName = _.get(details, 'tableName') || _.map(_.sortBy([strapi.models[details.collection].attributes[details.via], details], 'collection'), table => {
return _.snakeCase(pluralize.plural(table.collection) + ' ' + pluralize.plural(table.via)); return _.snakeCase(pluralize.plural(table.collection) + ' ' + pluralize.plural(table.via));
}).join('__'); }).join('__');

View File

@ -91,13 +91,29 @@ module.exports = strapi => {
client: connection.settings.client, client: connection.settings.client,
connection: { connection: {
host: _.get(connection.settings, 'host'), host: _.get(connection.settings, 'host'),
user: _.get(connection.settings, 'username'), user: _.get(connection.settings, 'username') || _.get(connection.settings, 'user'),
password: _.get(connection.settings, 'password'), password: _.get(connection.settings, 'password'),
database: _.get(connection.settings, 'database'), database: _.get(connection.settings, 'database'),
charset: _.get(connection.settings, 'charset') charset: _.get(connection.settings, 'charset'),
} schema: _.get(connection.settings, 'schema'),
},
debug: _.get(connection, 'debug') || false
}, strapi.config.hooks.knex); }, strapi.config.hooks.knex);
if (options.client === 'pg' && _.isString(_.get(options.connection, 'schema'))) {
options.pool = {
min: 0,
max: 10,
afterCreate: (conn, cb) => {
conn.query(`SET SESSION SCHEMA '${options.connection.schema}';`, (err) => {
cb(err, conn);
});
}
};
}
console.log(options);
// Finally, use the client via `knex`. // Finally, use the client via `knex`.
// If anyone has a solution to use different paths for `knex` and clients // If anyone has a solution to use different paths for `knex` and clients
// please drop us an email at support@strapi.io-- it would avoid the Strapi // please drop us an email at support@strapi.io-- it would avoid the Strapi