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

bookshelf

Package Overview
Dependencies
Maintainers
1
Versions
87
Alerts
File Explorer

Advanced tools

Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

bookshelf - npm Package Compare versions

Comparing version 0.2.1 to 0.2.2

72

bookshelf.js

@@ -1,2 +0,2 @@

// Bookshelf.js 0.2.1
// Bookshelf.js 0.2.2

@@ -28,3 +28,3 @@ // (c) 2013 Tim Griesser

// Keep in sync with `package.json`.
Bookshelf.VERSION = '0.2.1';
Bookshelf.VERSION = '0.2.2';

@@ -419,5 +419,2 @@ // We're using `Backbone.Events` rather than `EventEmitter`,

// Reset the model's `previousAttributes` and `changed` values.
model._reset();
return when.all([

@@ -427,3 +424,3 @@ model.trigger((method === 'insert' ? 'created' : 'updated'), model, resp, options),

]).then(function() {
return model;
return model._reset();
});

@@ -445,5 +442,4 @@ })

model.clear();
model._reset();
return model.triggerThen('destroyed', model, resp, options).then(function() {
return model;
return model._reset();
});

@@ -560,3 +556,3 @@ }).ensure(function() {

related: function(name) {
return this.relations[name] || (this.relations[name] = this[name]());
return this.relations[name] || (this[name] ? this.relations[name] = this[name]() : void 0);
},

@@ -691,13 +687,13 @@

fetch: function(options) {
var name, related, relation;
var key, relatedObj, name, related, relation;
var target = this.target;
var handled = this.handled = {};
var withRelated = options.withRelated;
var withRelated = this.prepWithRelated(options.withRelated);
var subRelated = {};
if (!_.isArray(withRelated)) withRelated = withRelated ? [withRelated] : [];
// Eager load each of the `withRelated` relation item, splitting on '.'
// which indicates a nested eager load.
for (var i = 0, l = options.withRelated.length; i < l; i++) {
related = options.withRelated[i].split('.');
for (key in withRelated) {
related = key.split('.');
name = related[0];

@@ -708,3 +704,5 @@

subRelated[name] || (subRelated[name] = []);
subRelated[name].push(related.slice(1).join('.'));
relatedObj = {};
relatedObj[related.slice(1).join('.')] = withRelated[key];
subRelated[name].push(relatedObj);
}

@@ -730,3 +728,3 @@

for (name in handled) {
pendingDeferred.push(this.eagerFetch(name, handled[name], _.extend({}, options, {
pendingDeferred.push(this.eagerFetch(name, handled[name], withRelated[name], _.extend({}, options, {
isEager: true,

@@ -745,9 +743,28 @@ withRelated: subRelated[name]

// Prep the `withRelated` object, to normalize into an object where each
// has a function that is called when running the query.
prepWithRelated: function(withRelated) {
if (!_.isArray(withRelated)) withRelated = withRelated ? [withRelated] : [];
var withRelatedObj = {};
for (var i = 0, l = withRelated.length; i < l; i++) {
if (_.isObject(withRelated[i])) {
_.extend(withRelatedObj, withRelated[i]);
continue;
}
withRelatedObj[withRelated[i]] = null;
}
return withRelatedObj;
},
// Handles an eager loaded fetch, passing the name of the item we're fetching for,
// and any options needed for the current fetch.
eagerFetch: function(name, handled, options) {
eagerFetch: function(name, handled, beforeFn, options) {
if (handled.type === 'morphTo') {
return this.morphToFetch(name, handled, options);
}
var that = this;
// Call the function, if one exists, to constrain the eager loaded query.
if (beforeFn) beforeFn.call(handled, handled.query());
var _this = this;
return handled

@@ -757,3 +774,3 @@ .sync(_.extend({}, options, {parentResponse: this.parentResponse}))

.then(function(resp) {
var relatedModels = that.pushModels(name, handled, resp);
var relatedModels = _this.pushModels(name, handled, resp);
// If there is a response, fetch additional nested eager relations, if any.

@@ -819,7 +836,6 @@ if (resp.length > 0 && options.withRelated) {

var related = new RelatedModels([]);
var models = related.models;
var relatedData = handled.relatedData;
var type = relatedData.type;
for (var i = 0, l = resp.length; i < l; i++) {
models.push(new relatedData.eager.ModelCtor(resp[i], {parse: true})._reset());
related.push(new relatedData.eager.ModelCtor(resp[i], {parse: true})._reset());
}

@@ -858,4 +874,12 @@ // Attach the appropriate related items onto the parent model.

};
_.extend(RelatedModels.prototype, _.pick(Collection.prototype, 'at', 'find', 'where', 'filter', 'findWhere', 'groupBy'));
_.extend(RelatedModels.prototype, _.pick(Collection.prototype, 'at', 'find', 'where', 'filter', 'findWhere', 'groupBy'), {
// Pushes a model onto the `RelatedModels` object, updates the length of the models array, and returns the added model.
push: function(model) {
this.length = this.models.push(model);
return model;
}
});
// Set up inheritance for the model and collection.

@@ -865,3 +889,3 @@ Model.extend = Collection.extend = EagerRelation.extend = Bookshelf.Backbone.Model.extend;

// The `forge` function properly instantiates a new Model or Collection
// without needing the "new" keyword... to make object creation cleaner
// without needing the "new" operator... to make object creation cleaner
// and more chainable.

@@ -1015,3 +1039,3 @@ Model.forge = Collection.forge = function() {

if (_.isString(column)) {
relatedData.pivotColumns.push(relatedData.joinTableName + '.' + column + ' as pivot_' + column);
relatedData.pivotColumns.push(relatedData.joinTableName + '.' + column + ' as _pivot_' + column);
} else {

@@ -1018,0 +1042,0 @@ for (var key in column) {

{
"name": "bookshelf",
"version": "0.2.1",
"version": "0.2.2",
"description": "A lightweight Active Record ORM for PostgreSQL, MySQL, and SQLite3, influenced by Backbone.js",

@@ -13,13 +13,7 @@ "main": "bookshelf.js",

"orm",
"query",
"mysql",
"postgres",
"postgresql",
"sqlite",
"sqlite3",
"knex",
"database",
"object relational mapper",
"datamapper",
"active record",
"polymorphic associations"
"active record"
],

@@ -26,0 +20,0 @@ "repository":{

@@ -217,3 +217,3 @@ var When = require('when');

});
equal(c.at(0).has('pivot_item'), true);
equal(c.at(0).has('_pivot_item'), true);
equal(c.length, 2);

@@ -220,0 +220,0 @@ }),

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