bookshelf-scopes
Advanced tools
Comparing version 1.0.2 to 1.1.0
{ | ||
"name": "bookshelf-scopes", | ||
"version": "1.0.2", | ||
"version": "1.1.0", | ||
"description": "Giving you Rails like scopes in Bookshelf.js.", | ||
@@ -5,0 +5,0 @@ "main": "src/scopes.js", |
@@ -8,3 +8,3 @@ # Bookshelf-Scopes | ||
bookshelf.plugin(scopes); | ||
bookshelf.plugin(require('bookshelf-scopes')); | ||
``` | ||
@@ -11,0 +11,0 @@ |
@@ -7,2 +7,3 @@ 'use strict'; | ||
var baseExtend = bookshelf.Model.extend; | ||
var QueryBuilder = bookshelf.knex().constructor; | ||
@@ -15,17 +16,25 @@ bookshelf.Model.extend = function(protoProps) { | ||
self.prototype[property] = function() { | ||
var _this = this; | ||
var passedInArguments = _.toArray(arguments); | ||
return this.query(function(qb) { | ||
passedInArguments.unshift(qb); | ||
self.scopes[property].apply(self.scopes, passedInArguments); | ||
}); | ||
if (passedInArguments.length > 0 && passedInArguments[0] instanceof QueryBuilder) { | ||
self.scopes[property].apply(this, passedInArguments); | ||
return self; | ||
} else { | ||
return this.query(function(qb) { | ||
passedInArguments.unshift(qb); | ||
self.scopes[property].apply(_this, passedInArguments); | ||
}); | ||
} | ||
}; | ||
self[property] = function() { | ||
return this.prototype[property].apply(this, arguments); | ||
} | ||
var model = this.forge(); | ||
return model[property].apply(model, arguments); | ||
}; | ||
}); | ||
return baseExtend.apply(self, arguments); | ||
} | ||
}; | ||
@@ -44,5 +53,5 @@ var Model = bookshelf.Model.extend({ | ||
self.query(function(qb) { | ||
var args = new Array(); | ||
var args = []; | ||
args.push(qb); | ||
self.scopes.default.apply(self.scopes, args); | ||
self.scopes.default.apply(self, args); | ||
}); | ||
@@ -62,2 +71,2 @@ } | ||
bookshelf.Model = Model; | ||
} | ||
}; |
'use strict'; | ||
var expect = require('chai').expect; | ||
var scopes = require('../src/scopes'); | ||
var Promise = require('bluebird'); | ||
@@ -13,3 +12,3 @@ | ||
var bookshelf = require('bookshelf')(knex); | ||
bookshelf.plugin(scopes); | ||
bookshelf.plugin(require('../src/scopes')); | ||
@@ -16,0 +15,0 @@ describe('scopes - basic scope', function() { |
'use strict'; | ||
var expect = require('chai').expect; | ||
var scopes = require('../src/scopes'); | ||
var Promise = require('bluebird'); | ||
@@ -13,3 +12,3 @@ | ||
var bookshelf = require('bookshelf')(knex); | ||
bookshelf.plugin(scopes); | ||
bookshelf.plugin(require('../src/scopes')); | ||
@@ -16,0 +15,0 @@ describe('scopes - default', function() { |
'use strict'; | ||
var expect = require('chai').expect; | ||
var scopes = require('../src/scopes'); | ||
var Promise = require('bluebird'); | ||
@@ -13,3 +12,3 @@ | ||
var bookshelf = require('bookshelf')(knex); | ||
bookshelf.plugin(scopes); | ||
bookshelf.plugin(require('../src/scopes')); | ||
@@ -16,0 +15,0 @@ describe('scopes - joining scope', function() { |
Sorry, the diff of this file is not supported yet
License Policy Violation
LicenseThis package is not allowed per your license policy. Review the package's license to ensure compliance.
Found 1 instance in 1 package
License Policy Violation
LicenseThis package is not allowed per your license policy. Review the package's license to ensure compliance.
Found 1 instance in 1 package
Native code
Supply chain riskContains native code (e.g., compiled binaries or shared libraries). Including native code can obscure malicious behavior.
Found 1 instance in 1 package
Major refactor
Supply chain riskPackage has recently undergone a major refactor. It may be unstable or indicate significant internal changes. Use caution when updating to versions that include significant changes.
Found 1 instance in 1 package
11
611
0
27414