Comparing version 0.6.7 to 0.6.8
@@ -1,2 +0,2 @@ | ||
// Bookshelf.js 0.6.7 | ||
// Bookshelf.js 0.6.8 | ||
// --------------- | ||
@@ -90,3 +90,3 @@ | ||
// Keep in sync with `package.json`. | ||
VERSION: '0.6.7', | ||
VERSION: '0.6.8', | ||
@@ -93,0 +93,0 @@ // Helper method to wrap a series of Bookshelf actions in a `knex` transaction block; |
@@ -17,2 +17,5 @@ // Base Model | ||
// List of attributes attached directly from the `options` passed to the constructor. | ||
var modelProps = ['tableName', 'hasTimestamps']; | ||
// The "ModelBase" is similar to the 'Active Model' in Rails, | ||
@@ -36,3 +39,3 @@ // it defines a standard interface from which other objects may | ||
_.extend(ModelBase.prototype, _.omit(Backbone.Model.prototype), Events, { | ||
_.extend(ModelBase.prototype, _.omit(Backbone.Model.prototype, modelOmitted), Events, { | ||
@@ -175,5 +178,2 @@ // Similar to the standard `Backbone` set method, but without individual | ||
// List of attributes attached directly from the `options` passed to the constructor. | ||
var modelProps = ['tableName', 'hasTimestamps']; | ||
ModelBase.extend = Backbone.Model.extend; | ||
@@ -180,0 +180,0 @@ |
@@ -70,3 +70,3 @@ // EagerRelation | ||
if (resp.length > 0 && options.withRelated) { | ||
var relatedModel = relatedData.createModel(resp[0]); | ||
var relatedModel = relatedData.createModel(); | ||
@@ -73,0 +73,0 @@ // If this is a `morphTo` relation, we need to do additional processing |
@@ -12,3 +12,3 @@ // Helpers | ||
if (relatedData && relatedData.type && relatedData.type !== 'belongsToMany') { | ||
data[relatedData.key('foreignKey')] = relatedData.parentFk; | ||
data[relatedData.key('foreignKey')] = relatedData.parentFk || model.get(relatedData.key('foreignKey')); | ||
if (relatedData.isMorph()) data[relatedData.key('morphKey')] = relatedData.key('morphValue'); | ||
@@ -15,0 +15,0 @@ } |
{ | ||
"name": "bookshelf", | ||
"version": "0.6.7", | ||
"version": "0.6.8", | ||
"description": "A lightweight ORM for PostgreSQL, MySQL, and SQLite3, influenced by Backbone.js", | ||
@@ -5,0 +5,0 @@ "main": "bookshelf.js", |
@@ -58,10 +58,12 @@ // Virtuals Plugin | ||
// Allow virtuals to be set like normal properties | ||
set: function (key, val, options) { | ||
if (key == null) return this; | ||
var virtuals = this.virtuals; | ||
var virtual = virtuals && virtuals[key]; | ||
if (virtual && virtual.set) { | ||
virtual.set.call(this, val); | ||
set: function(key, val, options) { | ||
if (key == null) { | ||
return this; | ||
} | ||
if (_.isObject(key)) { | ||
return proto.set.call(this, _.omit(key, setVirtual, this), val, options); | ||
} | ||
if (setVirtual.call(this, val, key)) { | ||
return this; | ||
} | ||
return proto.set.apply(this, arguments); | ||
@@ -101,3 +103,11 @@ } | ||
function setVirtual(value, key) { | ||
var virtual = this.virtuals && this.virtuals[key]; | ||
if (virtual && virtual.set) { | ||
virtual.set.call(this, value); | ||
return true; | ||
} | ||
} | ||
Bookshelf.Model = Model; | ||
}; |
@@ -153,2 +153,3 @@ var Promise = global.testPromise; | ||
return author.related('site').related('photos').create({ | ||
imageable_id: author.related('site').id, | ||
url: 'http://image.dev', | ||
@@ -160,2 +161,4 @@ caption: 'this is a test image' | ||
console.log('here'); | ||
expect(photo.get('url')).to.equal('http://image.dev'); | ||
@@ -162,0 +165,0 @@ |
@@ -61,2 +61,7 @@ var _ = require('lodash'); | ||
it('doesnt have ommitted Backbone properties', function() { | ||
expect(User.prototype.changedAttributes).to.be.undefined; | ||
expect((new User()).changedAttributes).to.be.undefined; | ||
}); | ||
}); | ||
@@ -63,0 +68,0 @@ |
@@ -69,4 +69,37 @@ var _ = require('lodash'); | ||
equal(m.get('lastName'), 'Shmoe'); | ||
// setting virtual should not set attribute | ||
equal(m.attributes['fullName'], undefined); | ||
m.set({fullName: 'Peter Griffin', dogName:'Brian'}); | ||
equal(m.get('firstName'), 'Peter'); | ||
equal(m.get('lastName'), 'Griffin'); | ||
equal(m.get('dogName'), 'Brian'); | ||
// setting virtual should not set attribute | ||
equal(m.attributes['fullName'], undefined); | ||
}); | ||
it('allows virtual properties to be set in the constructor', function () { | ||
var m = new (bookshelf.Model.extend({ | ||
virtuals: { | ||
fullName: { | ||
get: function () { | ||
return this.get('firstName') + ' ' + this.get('lastName'); | ||
}, | ||
set: function(value) { | ||
value = value.split(' '); | ||
this.set('firstName', value[0]); | ||
this.set('lastName', value[1]); | ||
} | ||
} | ||
} | ||
}))({fullName: 'Peter Griffin', dogName:'Brian'}); | ||
equal(m.get('firstName'), 'Peter'); | ||
equal(m.get('lastName'), 'Griffin'); | ||
equal(m.get('dogName'), 'Brian'); | ||
equal(m.attributes['fullName'], undefined); | ||
}); | ||
it('virtuals are included in the `toJSON` result by default', function () { | ||
@@ -73,0 +106,0 @@ var m = new (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
286783
7859