From 6e71a52e9026377b1b634327aed94ecaad11a90d Mon Sep 17 00:00:00 2001 From: Subramanian Krishnan Date: Fri, 26 Aug 2016 16:23:38 +0530 Subject: [PATCH] Make the app instance available to connectors --- lib/application.js | 1 + test/app.test.js | 6 ++++++ 2 files changed, 7 insertions(+) diff --git a/lib/application.js b/lib/application.js index f5df7871..6f6cb682 100644 --- a/lib/application.js +++ b/lib/application.js @@ -236,6 +236,7 @@ app.dataSource = function(name, config) { this.dataSources[name] = this.dataSources[classify(name)] = this.dataSources[camelize(name)] = ds; + ds.app = this; return ds; } catch (err) { if (err.message) { diff --git a/test/app.test.js b/test/app.test.js index fd2abfd8..ab1a0923 100644 --- a/test/app.test.js +++ b/test/app.test.js @@ -820,6 +820,12 @@ describe('app', function() { app.dataSource('bad-ds', { connector: 'throwing' }); }).to.throw(/bad-ds.*throwing/); }); + + it('adds app reference to the data source object', function() { + app.dataSource('ds', { connector: 'memory' }); + expect(app.datasources.ds.app).to.not.equal(undefined); + expect(app.datasources.ds.app).to.equal(app); + }); }); describe.onServer('listen()', function() {