Comparing version 0.1.0 to 0.1.1
@@ -1,2 +0,2 @@ | ||
// Bookshelf.js 0.1.0 | ||
// Bookshelf.js 0.1.1 | ||
@@ -25,3 +25,3 @@ // (c) 2013 Tim Griesser | ||
// Keep in sync with `package.json`. | ||
Bookshelf.VERSION = '0.1.0'; | ||
Bookshelf.VERSION = '0.1.1'; | ||
@@ -103,3 +103,6 @@ // We're using `Backbone.Events` rather than `EventEmitter`, | ||
var relation = this._relation; | ||
if (relation && relation.fkValue || resp) { | ||
if (relation) { | ||
if (!relation.fkValue && !resp) { | ||
return When.reject(new Error("The " + relation.otherKey + " must be specified.")); | ||
} | ||
if (relation.type !== 'belongsToMany') { | ||
@@ -111,2 +114,3 @@ constraints.call(this, resp); | ||
} | ||
return When.resolve(); | ||
} | ||
@@ -343,3 +347,3 @@ | ||
} | ||
options.parentIdAttr = _.result(this, 'idAttribute'); | ||
options.parentIdAttr = (type === 'belongsTo' ? options.otherKey : _.result(this, 'idAttribute')); | ||
} else { | ||
@@ -362,3 +366,3 @@ if (type === 'belongsTo') { | ||
} | ||
return target; | ||
@@ -370,3 +374,3 @@ }, | ||
_validate: function() { | ||
return true; | ||
return true; | ||
} | ||
@@ -590,3 +594,3 @@ | ||
builder = this.query(), | ||
tableName = _.result(this, 'tableName'), | ||
@@ -608,7 +612,7 @@ idAttribute = _.result(this, 'idAttribute'), | ||
); | ||
if (pivotColumns) push.apply(columns, pivotColumns); | ||
builder.join(joinTableName, tableName + '.' + idAttribute, '=', joinTableName + '.' + foreignKey); | ||
if (resp) { | ||
@@ -631,6 +635,7 @@ builder.whereIn(joinTableName + '.' + otherKey, _.pluck(resp, idAttribute)); | ||
this._addConstraints(relation.parentResponse); | ||
return this._addConstraints(relation.parentResponse).then(function() { | ||
return current.query().select(relation.columns); | ||
}) | ||
.then(function(resp) { | ||
return this.query().select(relation.columns).then(function(resp) { | ||
// Only find additional related items & process if | ||
@@ -652,3 +657,3 @@ // there is a response from the query. | ||
return models; | ||
}).ensure(function() { | ||
@@ -686,3 +691,3 @@ current.resetQuery(); | ||
this.query = model.query(); | ||
model._addConstraints(); | ||
if (options.transacting) this.query.transacting(options.transacting); | ||
@@ -705,16 +710,22 @@ }; | ||
select: function() { | ||
var sync = this; | ||
var options = sync.options; | ||
var model = this.model; | ||
var options = this.options; | ||
var columns = options.columns; | ||
if (!_.isArray(columns)) columns = columns ? [columns] : ['*']; | ||
if (model._relation && model._relation.columns) { | ||
columns = model._relation.columns; | ||
} | ||
return this.query.select(columns).then(function(resp) { | ||
return model._addConstraints().then(function() { | ||
var columns = options.columns; | ||
if (!_.isArray(columns)) columns = columns ? [columns] : ['*']; | ||
if (model._relation && model._relation.columns) { | ||
columns = model._relation.columns; | ||
} | ||
return sync.query.select(columns); | ||
}) | ||
.then(function(resp) { | ||
var target; | ||
if (resp && resp.length > 0) { | ||
// If this is a model fetch, then we set the parsed attributes | ||
@@ -727,3 +738,3 @@ // on the model, otherwise, we reset the collection. | ||
} | ||
// If the `withRelated` property is specified on the options hash, we dive | ||
@@ -739,3 +750,3 @@ // into the `EagerRelation`. If the current querying object is a collection, | ||
} | ||
return resp; | ||
@@ -755,3 +766,3 @@ } | ||
return []; | ||
}).then(function(resp) { | ||
@@ -758,0 +769,0 @@ if (resp.length > 0) { |
{ | ||
"name": "bookshelf", | ||
"author": "Tim Griesser", | ||
"version": "0.1.0", | ||
"version": "0.1.1", | ||
"description": "An ORM with some Backbone", | ||
@@ -6,0 +6,0 @@ "main": "bookshelf.js", |
@@ -33,3 +33,3 @@ var When = require('when'); | ||
it('handles belongsTo', function(ok) { | ||
var responses = []; | ||
@@ -49,3 +49,3 @@ | ||
}); | ||
it('handles hasMany', function(ok) { | ||
@@ -91,3 +91,3 @@ new Blog({id: 1}) | ||
it('eager loads "belongsTo" relationships correctly', function(ok) { | ||
new Blog({id: 1}).fetch({ | ||
new Blog({id: 3}).fetch({ | ||
withRelated: ['site'] | ||
@@ -97,2 +97,8 @@ }).then(handler(ok), ok); | ||
it('Throws an error if you try to fetch a related object without the necessary key', function(ok) { | ||
new Blog({id: 1}).site().fetch().then(null, function() { | ||
ok(); | ||
}); | ||
}); | ||
it('eager loads "belongsToMany" models correctly', function(ok) { | ||
@@ -138,3 +144,3 @@ new Post({id: 1}).fetch({ | ||
describe('Nested Eager Loading - Models', function() { | ||
it('eager loads "hasMany" -> "hasMany"', function(ok) { | ||
@@ -192,3 +198,3 @@ new Site({id: 1}).fetch({ | ||
var admin2 = new Admin({username: 'syncable', password: 'test'}); | ||
When.all([admin1.save(), admin2.save()]) | ||
@@ -223,2 +229,5 @@ .then(function() { | ||
}); | ||
}) | ||
.then(null, function(e) { | ||
console.log(e.stack); | ||
}); | ||
@@ -225,0 +234,0 @@ }); |
@@ -328,26 +328,26 @@ module.exports = { | ||
mysql: { | ||
id: 1, | ||
site_id: 1, | ||
id: 3, | ||
site_id: 2, | ||
name: 'Main Site Blog', | ||
site: { | ||
id: 1, | ||
name: 'knexjs.org' | ||
id: 2, | ||
name: 'bookshelfjs.org' | ||
} | ||
}, | ||
postgres: { | ||
id: 1, | ||
site_id: 1, | ||
id: 3, | ||
site_id: 2, | ||
name: 'Main Site Blog', | ||
site: { | ||
id: 1, | ||
name: 'knexjs.org' | ||
id: 2, | ||
name: 'bookshelfjs.org' | ||
} | ||
}, | ||
sqlite3: { | ||
id: 1, | ||
site_id: 1, | ||
id: 3, | ||
site_id: 2, | ||
name: 'Main Site Blog', | ||
site: { | ||
id: 1, | ||
name: 'knexjs.org' | ||
id: 2, | ||
name: 'bookshelfjs.org' | ||
} | ||
@@ -354,0 +354,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
Non-existent author
Supply chain riskThe package was published by an npm account that no longer exists.
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
130806
3509
0
1