Huge News!Announcing our $40M Series B led by Abstract Ventures.Learn More
Socket
Sign inDemoInstall
Socket

bookshelf-scopes

Package Overview
Dependencies
Maintainers
1
Versions
14
Alerts
File Explorer

Advanced tools

Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

bookshelf-scopes - npm Package Compare versions

Comparing version 1.3.0 to 1.4.0

2

package.json
{
"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({

SocketSocket SOC 2 Logo

Product

  • Package Alerts
  • Integrations
  • Docs
  • Pricing
  • FAQ
  • Roadmap
  • Changelog

Packages

npm

Stay in touch

Get open source security insights delivered straight into your inbox.


  • Terms
  • Privacy
  • Security

Made with ⚡️ by Socket Inc