diff --git a/lib/discovery.js b/lib/discovery.js index 2ff4696..46429b0 100644 --- a/lib/discovery.js +++ b/lib/discovery.js @@ -177,6 +177,9 @@ function mixinDiscovery(MySQL) { MySQL.prototype.discoverModelProperties = function (table, options, cb) { var args = getArgs(table, options, cb); var owner = args.owner; + if(!owner){ + owner = inheritOwnerViaDataSource.call(this); + } table = args.table; options = args.options; cb = args.cb; @@ -228,6 +231,9 @@ function mixinDiscovery(MySQL) { MySQL.prototype.discoverPrimaryKeys = function (table, options, cb) { var args = getArgs(table, options, cb); var owner = args.owner; + if(!owner){ + owner = inheritOwnerViaDataSource.call(this); + } table = args.table; options = args.options; cb = args.cb; @@ -269,6 +275,9 @@ function mixinDiscovery(MySQL) { MySQL.prototype.discoverForeignKeys = function (table, options, cb) { var args = getArgs(table, options, cb); var owner = args.owner; + if(!owner){ + owner = inheritOwnerViaDataSource.call(this); + } table = args.table; options = args.options; cb = args.cb; @@ -312,6 +321,9 @@ function mixinDiscovery(MySQL) { MySQL.prototype.discoverExportedForeignKeys = function (table, options, cb) { var args = getArgs(table, options, cb); var owner = args.owner; + if(!owner){ + owner = inheritOwnerViaDataSource.call(this); + } table = args.table; options = args.options; cb = args.cb; @@ -366,4 +378,11 @@ function mixinDiscovery(MySQL) { return 'String'; } } + + function inheritOwnerViaDataSource(){ + if(this.dataSource && this.dataSource.settings && this.dataSource.settings.database){ + return this.dataSource.settings.database; + } + return undefined; + } }