Inherit Schema From DataSource if not defined

If owner is not set via json in the discovery process, use the database
schema defined in the dataSource setting.
This commit is contained in:
Serkan Serttop 2014-11-30 02:40:41 +02:00
parent f130b8c5fa
commit 78476b5a9a
1 changed files with 19 additions and 0 deletions

View File

@ -167,6 +167,9 @@ function mixinDiscovery(MySQL) {
MySQL.prototype.discoverModelProperties = function (table, options, cb) { MySQL.prototype.discoverModelProperties = function (table, options, cb) {
var args = getArgs(table, options, cb); var args = getArgs(table, options, cb);
var owner = args.owner; var owner = args.owner;
if(!owner){
owner = inheritOwnerViaDataSource.call(this);
}
table = args.table; table = args.table;
options = args.options; options = args.options;
cb = args.cb; cb = args.cb;
@ -217,6 +220,9 @@ function mixinDiscovery(MySQL) {
MySQL.prototype.discoverPrimaryKeys = function (table, options, cb) { MySQL.prototype.discoverPrimaryKeys = function (table, options, cb) {
var args = getArgs(table, options, cb); var args = getArgs(table, options, cb);
var owner = args.owner; var owner = args.owner;
if(!owner){
owner = inheritOwnerViaDataSource.call(this);
}
table = args.table; table = args.table;
options = args.options; options = args.options;
cb = args.cb; cb = args.cb;
@ -258,6 +264,9 @@ function mixinDiscovery(MySQL) {
MySQL.prototype.discoverForeignKeys = function (table, options, cb) { MySQL.prototype.discoverForeignKeys = function (table, options, cb) {
var args = getArgs(table, options, cb); var args = getArgs(table, options, cb);
var owner = args.owner; var owner = args.owner;
if(!owner){
owner = inheritOwnerViaDataSource.call(this);
}
table = args.table; table = args.table;
options = args.options; options = args.options;
cb = args.cb; cb = args.cb;
@ -301,6 +310,9 @@ function mixinDiscovery(MySQL) {
MySQL.prototype.discoverExportedForeignKeys = function (table, options, cb) { MySQL.prototype.discoverExportedForeignKeys = function (table, options, cb) {
var args = getArgs(table, options, cb); var args = getArgs(table, options, cb);
var owner = args.owner; var owner = args.owner;
if(!owner){
owner = inheritOwnerViaDataSource.call(this);
}
table = args.table; table = args.table;
options = args.options; options = args.options;
cb = args.cb; cb = args.cb;
@ -355,4 +367,11 @@ function mixinDiscovery(MySQL) {
return 'String'; return 'String';
} }
} }
function inheritOwnerViaDataSource(){
if(this.dataSource && this.dataSource.settings && this.dataSource.settings.database){
return this.dataSource.settings.database;
}
return undefined;
}
} }