bookshelf-scopes
Advanced tools
Comparing version 1.3.0 to 1.4.0
{ | ||
"name": "bookshelf-scopes", | ||
"version": "1.3.0", | ||
"version": "1.4.0", | ||
"description": "Giving you Rails like scopes in Bookshelf.js.", | ||
@@ -5,0 +5,0 @@ "main": "src/scopes.js", |
@@ -67,3 +67,3 @@ 'use strict'; | ||
passedInArguments.unshift(knex); | ||
target.prototype.scopes[key].apply(this, passedInArguments); | ||
target.prototype.scopes[key].apply(target.prototype, passedInArguments); | ||
}; | ||
@@ -70,0 +70,0 @@ return relationship; |
@@ -198,2 +198,37 @@ 'use strict'; | ||
it('Can access prototype variables from related', function() { | ||
var TestModel1 = bookshelf.Model.extend({ | ||
tableName: 'testmodel', | ||
scopes: { | ||
active: function(qb) { | ||
if (this !== TestModel1.prototype) { | ||
throw new Error('this not set to target prototype'); | ||
} | ||
qb.where({'archived': false}); | ||
} | ||
} | ||
}); | ||
var TestRole = bookshelf.Model.extend({ | ||
tableName: 'testrole', | ||
test_models: function() { | ||
return this.hasMany(TestModel1).active(); | ||
} | ||
}); | ||
return Promise.all([ | ||
TestModel1.forge({name: 'test1', testrole_id: 1, archived: true}).save(), | ||
TestModel1.forge({name: 'test2', testrole_id: 1, archived: false}).save(), | ||
TestRole.forge({name: 'Company'}).save() | ||
]).then(function() { | ||
return TestRole.fetchAll({ | ||
withRelated: ['test_models'] | ||
}).then(function(allRoles) { | ||
expect(allRoles.length).to.equal(1); | ||
expect(allRoles.at(0).related('test_models').length).to.equal(1); | ||
}); | ||
}); | ||
}); | ||
it('Can call unscoped on related', function() { | ||
@@ -200,0 +235,0 @@ var TestModel1 = bookshelf.Model.extend({ |
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
43830
1059