Skip to content
This repository has been archived by the owner on Aug 5, 2021. It is now read-only.

Commit

Permalink
update documentation + fix test
Browse files Browse the repository at this point in the history
  • Loading branch information
Philipp Waldmann committed Oct 13, 2014
1 parent 6bc5e86 commit 7f93c82
Show file tree
Hide file tree
Showing 5 changed files with 33 additions and 4 deletions.
2 changes: 2 additions & 0 deletions documentation/Home.md
Expand Up @@ -319,6 +319,8 @@ Scopes are synchronous only and will provide automatic [chainability](#chaining)
{{Definition.scope()}}
{{Definition.defaultScope()}}
## Custom Methods
Expand Down
4 changes: 4 additions & 0 deletions lib/base/context.js
Expand Up @@ -19,6 +19,10 @@ exports.model = {

self.setInternal('context', context);

self.callInterceptors('onContext', [context], function(okay){
//we use interceptors here even though there isn't anything to intercept...
});

return self;
}
};
Expand Down
17 changes: 16 additions & 1 deletion lib/base/interceptors.js
Expand Up @@ -64,7 +64,22 @@ exports.store = {
*
* @return {Definition}
*/
this.addInterceptor('afterValidation');
this.addInterceptor('afterValidation');


/**
* Will be called after a new context was set. This hook will be called by `Model.setContext()`.
* @class Definition
* @method onContext
* @param {function} callback - Your interceptor function
*
* @callback
* @param {Object} context - The current context
* @this Model
*
* @return {Definition}
*/
this.addInterceptor('onContext');
},

addInterceptor: function(name){
Expand Down
11 changes: 10 additions & 1 deletion lib/base/scope.js
Expand Up @@ -41,9 +41,18 @@ exports.definition = {




/**
* Adds a default scope
*
* @class Definition
* @method defaultScope
* @param {string} name - The name of the scope
*
* @return {Definition}
*/
defaultScope: function(name){
this.default_scopes.push(name);
return this;
}
};

Expand Down
3 changes: 1 addition & 2 deletions test/sql/__shared/includes-test.js
Expand Up @@ -542,7 +542,7 @@ module.exports = function(title, beforeFn, afterFn, store_conf){
User.include('user').exec(function(result){
result.length.should.be.equal(3);

result[0].login.should.be.equal(result[0].user.login);
result[0].id.should.be.equal(result[0].user.id);
result[0].email.should.not.be.equal(result[0].user.email);

next();
Expand All @@ -561,7 +561,6 @@ module.exports = function(title, beforeFn, afterFn, store_conf){

result[0].user.posts.length.should.be.equal(3);
result[1].user.posts.length.should.be.equal(1);
result[2].user.posts.length.should.be.equal(0);

next();
}).catch(function(err){
Expand Down

0 comments on commit 7f93c82

Please sign in to comment.