bookshelf-scopes
Advanced tools
Comparing version 1.2.0 to 1.2.1
{ | ||
"name": "bookshelf-scopes", | ||
"version": "1.2.0", | ||
"version": "1.2.1", | ||
"description": "Giving you Rails like scopes in Bookshelf.js.", | ||
@@ -5,0 +5,0 @@ "main": "src/scopes.js", |
@@ -6,2 +6,3 @@ 'use strict'; | ||
module.exports = function(bookshelf) { | ||
var base = bookshelf.Model; | ||
var baseExtend = bookshelf.Model.extend; | ||
@@ -11,3 +12,3 @@ // `bookshelf.knex()` was deprecated in knex v0.8.0, use `knex.queryBuilder()` instead if available | ||
bookshelf.Model.extend = function(protoProps) { | ||
bookshelf.Model.extend = function(protoProps, constructorProps) { | ||
var model = baseExtend.apply(this, arguments); | ||
@@ -47,7 +48,9 @@ | ||
var relationship = original.apply(this, arguments); | ||
if (relationship.model.prototype.scopes && relationship.model.prototype.scopes.default) { | ||
var target = relationship.model || relationship.relatedData.target; | ||
if (target.prototype.scopes && target.prototype.scopes.default) { | ||
var originalSelectConstraints = relationship.relatedData.selectConstraints; | ||
relationship.relatedData.selectConstraints = function(knex, options) { | ||
originalSelectConstraints.apply(this, arguments); | ||
relationship.model.prototype.scopes.default.apply(this, [knex]); | ||
target.prototype.scopes.default.apply(this, [knex]); | ||
}; | ||
@@ -75,5 +78,3 @@ } | ||
self.query(function(qb) { | ||
var args = []; | ||
args.push(qb); | ||
self.scopes.default.apply(self, args); | ||
self.scopes.default.call(self, qb); | ||
}); | ||
@@ -80,0 +81,0 @@ } |
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
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
7859
0