Comparing version 0.6.10 to 0.6.11
@@ -1,2 +0,2 @@ | ||
// Bookshelf.js 0.6.10 | ||
// Bookshelf.js 0.6.11 | ||
// --------------- | ||
@@ -51,3 +51,3 @@ | ||
throw new Error('A valid target model must be defined for the ' + | ||
_.result(this, 'tableName') + ' ' + type + 'relation'); | ||
_.result(this, 'tableName') + ' ' + type + ' relation'); | ||
} | ||
@@ -91,3 +91,3 @@ return new Relation(type, Target, options); | ||
// Keep in sync with `package.json`. | ||
VERSION: '0.6.10', | ||
VERSION: '0.6.11', | ||
@@ -94,0 +94,0 @@ // Helper method to wrap a series of Bookshelf actions in a `knex` transaction block; |
@@ -11,3 +11,3 @@ // Helpers | ||
var data = {}; | ||
if (relatedData && relatedData.type && relatedData.type !== 'belongsToMany') { | ||
if (relatedData && relatedData.type && relatedData.type !== 'belongsToMany' && relatedData.type !== 'belongsTo') { | ||
data[relatedData.key('foreignKey')] = relatedData.parentFk || model.get(relatedData.key('foreignKey')); | ||
@@ -14,0 +14,0 @@ if (relatedData.isMorph()) data[relatedData.key('morphKey')] = relatedData.key('morphValue'); |
{ | ||
"name": "bookshelf", | ||
"version": "0.6.10", | ||
"version": "0.6.11", | ||
"description": "A lightweight ORM for PostgreSQL, MySQL, and SQLite3, influenced by Backbone.js", | ||
@@ -25,2 +25,5 @@ "main": "bookshelf.js", | ||
], | ||
"peerDependencies": { | ||
"knex": "0.5.x" | ||
}, | ||
"dependencies": { | ||
@@ -30,3 +33,2 @@ "backbone": "1.1.0", | ||
"trigger-then": "0.3.x", | ||
"knex": "0.5.x", | ||
"bluebird": "1.2.x", | ||
@@ -48,3 +50,4 @@ "lodash": ">=2.0.0" | ||
"sinon": "~1.7.3", | ||
"node-uuid": "~1.4.1" | ||
"node-uuid": "~1.4.1", | ||
"knex": "0.5.x" | ||
}, | ||
@@ -51,0 +54,0 @@ "author": { |
@@ -6,10 +6,15 @@ // Registry Plugin - | ||
module.exports = function (Bookshelf) { | ||
"use strict"; | ||
'use strict'; | ||
var _ = require('lodash'); | ||
function preventOverwrite(store, name) { | ||
if (store[name]) throw new Error(name + ' is already defined in the registry'); | ||
} | ||
// Set up the methods for storing and retrieving models | ||
// on the Bookshelf instance. | ||
Bookshelf.model = function(name, ModelCtor) { | ||
this._models = this._models || {}; | ||
this._models = this._models || Object.create(null); | ||
if (ModelCtor) { | ||
preventOverwrite(this._models, name); | ||
this._models[name] = ModelCtor; | ||
@@ -20,4 +25,5 @@ } | ||
Bookshelf.collection = function(name, CollectionCtor) { | ||
this._collections = this._collections || {}; | ||
this._collections = this._collections || Object.create(null); | ||
if (CollectionCtor) { | ||
preventOverwrite(this._collections, name); | ||
this._collections[name] = CollectionCtor; | ||
@@ -24,0 +30,0 @@ } |
@@ -17,8 +17,8 @@ var Promise = require('../dialects/base/promise').Promise; | ||
global.sinon = require("sinon"); | ||
global.sinon = require('sinon'); | ||
var chai = global.chai = require("chai"); | ||
var chai = global.chai = require('chai'); | ||
chai.use(require("chai-as-promised")); | ||
chai.use(require("sinon-chai")); | ||
chai.use(require('chai-as-promised')); | ||
chai.use(require('sinon-chai')); | ||
chai.should(); | ||
@@ -25,0 +25,0 @@ |
@@ -1,5 +0,3 @@ | ||
var assert = require('assert'), | ||
equal = assert.equal, | ||
_ = require('lodash'), | ||
sinon = require('sinon'); | ||
var expect = require('chai').expect; | ||
var sinon = require('sinon'); | ||
@@ -20,3 +18,3 @@ module.exports = function(Bookshelf) { | ||
beforeEach(function() { | ||
beforeEach(function () { | ||
this.hasOne.reset(); | ||
@@ -41,12 +39,11 @@ this.morphTo.reset(); | ||
it('returns the registered model', function() { | ||
equal(this.model, this.Model); | ||
expect(this.model).to.equal(this.Model); | ||
}); | ||
it('assigns the model the name', function() { | ||
equal(Bookshelf.model('Model'), this.Model); | ||
expect(Bookshelf.model('Model')).to.equal(this.Model); | ||
}); | ||
it('overwrites when there is a name conflict', function() { | ||
Bookshelf.model('Model', Bookshelf.Model); | ||
equal(Bookshelf.model('Model'), Bookshelf.Model); | ||
it('throws when there is a name conflict', function() { | ||
expect(Bookshelf.model.bind(Bookshelf, 'Model', Bookshelf.Model)).to.throw(); | ||
}); | ||
@@ -67,12 +64,11 @@ | ||
it('returns the registered collection', function() { | ||
equal(this.collection, this.Collection); | ||
expect(this.collection).to.equal(this.Collection); | ||
}); | ||
it('gives the collection a name', function() { | ||
equal(Bookshelf.collection('Collection'), this.Collection); | ||
expect(Bookshelf.collection('Collection')).to.equal(this.Collection); | ||
}); | ||
it('overwrites the collection when there is a name conflict', function() { | ||
Bookshelf.collection('Collection', Bookshelf.Collection); | ||
equal(Bookshelf.collection('Collection'), Bookshelf.Collection); | ||
it('throws when there is a name conflict', function() { | ||
expect(Bookshelf.collection.bind(Bookshelf, 'Collection', Bookshelf.Collection)).to.throw(); | ||
}); | ||
@@ -111,12 +107,17 @@ | ||
afterEach(function () { | ||
delete Bookshelf._models; | ||
delete Bookshelf._collections; | ||
}); | ||
it('resolves a string name to a model', function() { | ||
equal(this.model._hasOne().relatedData.target, this.relatedModel); | ||
expect(this.model._hasOne().relatedData.target).to.equal(this.relatedModel); | ||
}); | ||
it('falls back to a collection if no model is found', function() { | ||
equal(this.model._hasMany().relatedData.target, this.relatedCollection); | ||
expect(this.model._hasMany().relatedData.target).to.equal(this.relatedCollection); | ||
}); | ||
it('can still accept a model constructor', function() { | ||
equal(this.model._normalHasOne().relatedData.target, this.relatedModel); | ||
expect(this.model._normalHasOne().relatedData.target).to.equal(this.relatedModel); | ||
}); | ||
@@ -126,3 +127,3 @@ | ||
this.model._hasOne(); | ||
sinon.assert.calledWith(this.hasOne, this.relatedModel); | ||
expect(this.hasOne).to.have.been.calledWith(this.relatedModel); | ||
}); | ||
@@ -145,3 +146,3 @@ | ||
} catch (e) { | ||
sinon.assert.calledWith(this.morphTo, 'morphable', this.relatedModel, this.relatedModel); | ||
expect(this.morphTo).to.have.been.calledWith('morphable', this.relatedModel, this.relatedModel); | ||
} | ||
@@ -148,0 +149,0 @@ }); |
@@ -706,5 +706,21 @@ var _ = require('lodash'); | ||
}); | ||
describe('Issue #353 - wrong key set on a belongsTo relation', function() { | ||
it('should not set the foreign key on the target model when saving', function() { | ||
return new Blog({id: 4}) | ||
.fetch() | ||
.then(function(model) { | ||
return model.site().fetch(); | ||
}) | ||
.then(function (site) { | ||
return site.save(); | ||
}); | ||
}); | ||
}); | ||
}); | ||
}; |
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
288652
7916
14
- Removedknex@0.5.x