1
1
!function(e){if("object"==typeof exports&&"undefined"!=typeof module)module.exports=e();else if("function"==typeof define&&define.amd)define([],e);else{var f;"undefined"!=typeof window?f=window:"undefined"!=typeof global?f=global:"undefined"!=typeof self&&(f=self),f.Bookshelf=e()}}(function(){var define,module,exports;return (function e(t,n,r){function s(o,u){if(!n[o]){if(!t[o]){var a=typeof require=="function"&&require;if(!u&&a)return a(o,!0);if(i)return i(o,!0);var f=new Error("Cannot find module '"+o+"'");throw f.code="MODULE_NOT_FOUND",f}var l=n[o]={exports:{}};t[o][0].call(l.exports,function(e){var n=t[o][1][e];return s(n?n:e)},l,l.exports,e,t,n,r)}return n[o].exports}var i=typeof require=="function"&&require;for(var o=0;o<r.length;o++)s(r[o]);return s})({1:[function(require,module,exports){
2
- // Bookshelf.js 0.7.8
2
+ // Bookshelf.js 0.7.9
3
3
// ---------------
4
4
5
5
// (c) 2014 Tim Griesser
@@ -16,7 +16,7 @@ var Bookshelf = function() {
16
16
// `Model` and `Collection` constructors for use in the current instance.
17
17
Bookshelf.initialize = function(knex) {
18
18
var bookshelf = {
19
- VERSION: '0.7.8 '
19
+ VERSION: '0.7.9 '
20
20
};
21
21
22
22
var _ = require('lodash');
@@ -1437,6 +1437,12 @@ _.extend(BookshelfRelation.prototype, {
1437
1437
selectConstraints: function(knex, options) {
1438
1438
var resp = options.parentResponse;
1439
1439
1440
+ // The `belongsToMany` and `through` relations have joins & pivot columns.
1441
+ if (this.isJoined()) this.joinClauses(knex);
1442
+
1443
+ // Call the function, if one exists, to constrain the eager loaded query.
1444
+ if (options._beforeFn) options._beforeFn.call(knex, knex);
1445
+
1440
1446
// The base select column
1441
1447
if (_.isArray(options.columns)) {
1442
1448
knex.columns(options.columns);
@@ -1448,12 +1454,8 @@ _.extend(BookshelfRelation.prototype, {
1448
1454
knex.column(this.targetTableName + '.*');
1449
1455
}
1450
1456
1451
- // The `belongsToMany` and `through` relations have joins & pivot columns.
1452
- if (this.isJoined()) {
1453
- this.joinClauses(knex);
1454
- this.joinColumns(knex);
1455
- }
1456
-
1457
+ if (this.isJoined()) this.joinColumns(knex);
1458
+
1457
1459
// If this is a single relation and we're not eager loading,
1458
1460
// limit the query to a single item.
1459
1461
if (this.isSingle() && !resp) knex.limit(1);
@@ -1856,28 +1858,28 @@ _.extend(Sync.prototype, {
1856
1858
select: Promise.method(function() {
1857
1859
var columns, sync = this,
1858
1860
options = this.options, relatedData = this.syncing.relatedData;
1861
+ var knex = this.query;
1859
1862
1860
1863
// Inject all appropriate select costraints dealing with the relation
1861
1864
// into the `knex` query builder for the current instance.
1862
1865
if (relatedData) {
1863
- relatedData.selectConstraints(this.query , options);
1866
+ relatedData.selectConstraints(knex , options);
1864
1867
} else {
1865
1868
columns = options.columns;
1869
+ // Call the function, if one exists, to constrain the eager loaded query.
1870
+ if (options._beforeFn) options._beforeFn.call(knex, knex);
1866
1871
if (!_.isArray(columns)) columns = columns ? [columns] : [_.result(this.syncing, 'tableName') + '.*'];
1867
1872
}
1868
1873
1869
1874
// Set the query builder on the options, in-case we need to
1870
1875
// access in the `fetching` event handlers.
1871
- options.query = this.query;
1872
-
1873
- // Call the function, if one exists, to constrain the eager loaded query.
1874
- if (options._beforeFn) options._beforeFn.call(this.syncing, options.query);
1876
+ options.query = knex;
1875
1877
1876
1878
// Trigger a `fetching` event on the model, and then select the appropriate columns.
1877
1879
return Promise.bind(this).then(function() {
1878
1880
return this.syncing.triggerThen('fetching', this.syncing, columns, options);
1879
1881
}).then(function() {
1880
- return this.query .select(columns);
1882
+ return knex .select(columns);
1881
1883
});
1882
1884
}),
1883
1885
0 commit comments