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() {