From 78476b5a9ac1fbcdce43ce704454c3145af434fe Mon Sep 17 00:00:00 2001 From: Serkan Serttop Date: Sun, 30 Nov 2014 02:40:41 +0200 Subject: [PATCH] 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. --- lib/discovery.js | 19 +++++++++++++++++++ 1 file changed, 19 insertions(+) diff --git a/lib/discovery.js b/lib/discovery.js index 087cbab..43701c0 100644 --- a/lib/discovery.js +++ b/lib/discovery.js @@ -167,6 +167,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; @@ -217,6 +220,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; @@ -258,6 +264,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; @@ -301,6 +310,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; @@ -355,4 +367,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; + } }