mirror of
https://github.com/strapi/strapi.git
synced 2025-08-19 22:27:18 +00:00
Allow custom tableName on M2M associations and select PG schema
This commit is contained in:
parent
206d673822
commit
9aa2cedf85
@ -192,7 +192,7 @@ module.exports = function (strapi) {
|
||||
break;
|
||||
}
|
||||
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));
|
||||
}).join('__');
|
||||
|
||||
|
@ -91,13 +91,29 @@ module.exports = strapi => {
|
||||
client: connection.settings.client,
|
||||
connection: {
|
||||
host: _.get(connection.settings, 'host'),
|
||||
user: _.get(connection.settings, 'username'),
|
||||
user: _.get(connection.settings, 'username') || _.get(connection.settings, 'user'),
|
||||
password: _.get(connection.settings, 'password'),
|
||||
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);
|
||||
|
||||
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`.
|
||||
// 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
|
||||
|
Loading…
x
Reference in New Issue
Block a user