diff --git a/lib/scope.js b/lib/scope.js index 09ce1305..f84d4bee 100644 --- a/lib/scope.js +++ b/lib/scope.js @@ -52,7 +52,7 @@ ScopeDefinition.prototype.related = function(receiver, scopeParams, condOrRefres var actualCond = {}; var actualRefresh = false; - var saveOnCache = true; + var saveOnCache = receiver instanceof DefaultModelBaseClass; if (typeof condOrRefresh === 'function' && options === undefined && cb === undefined) { // related(receiver, scopeParams, cb) diff --git a/test/scope.test.js b/test/scope.test.js index 04c5132e..bf59342b 100644 --- a/test/scope.test.js +++ b/test/scope.test.js @@ -75,6 +75,28 @@ describe('scope', function () { }); }); }); + + it('should not cache any results', function (done) { + Station.scope('active', {where: {isActive: true}}); + Station.active.create(function (err, s) { + if (err) return done(err); + s.isActive.should.be.true; + Station.active(function(err, ss) { + if (err) return done(err); + ss.should.have.lengthOf(1); + ss[0].id.should.eql(s.id); + s.updateAttribute('isActive', false, function(err, s) { + if (err) return done(err); + s.isActive.should.be.false; + Station.active(function(err, ss) { + if (err) return done(err); + ss.should.have.lengthOf(0); + done(); + }); + }); + }); + }); + }); });