Skip to content

Commit 4622d8b

Browse files
author
Mike Eldridge
committed
Merge branch 'master' into gh-issue-10-transaction-support
2 parents b1ec3de + 800788e commit 4622d8b

File tree

5 files changed

+43
-24
lines changed

5 files changed

+43
-24
lines changed

dist/js-data-sql.js

Lines changed: 18 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -53,10 +53,10 @@ module.exports =
5353

5454
function _defineProperty(obj, key, value) { if (key in obj) { Object.defineProperty(obj, key, { value: value, enumerable: true, configurable: true, writable: true }); } else { obj[key] = value; } return obj; }
5555

56-
var knex = __webpack_require__(1);
57-
var JSData = __webpack_require__(2);
58-
var map = __webpack_require__(3);
59-
var underscore = __webpack_require__(4);
56+
var knex = __webpack_require__(2);
57+
var JSData = __webpack_require__(3);
58+
var map = __webpack_require__(4);
59+
var underscore = __webpack_require__(1);
6060
var unique = __webpack_require__(5);
6161
var toString = __webpack_require__(6);
6262
var DSUtils = JSData.DSUtils;
@@ -123,14 +123,18 @@ module.exports =
123123

124124
var relation = _localResourceConfig$relationList$filter2[0];
125125

126-
var _table = getTable(localResourceConfig);
127-
var localId = _table + '.' + relation.localKey;
126+
if (relation) {
127+
var _table = getTable(localResourceConfig);
128+
var localId = _table + '.' + relation.localKey;
128129

129-
var relationTable = getTable(relationResourceConfig);
130-
var foreignId = relationTable + '.' + relationResourceConfig.idAttribute;
130+
var relationTable = getTable(relationResourceConfig);
131+
var foreignId = relationTable + '.' + relationResourceConfig.idAttribute;
131132

132-
query = query.join(relationTable, localId, foreignId);
133-
joinedTables.push(relationPath.join('.'));
133+
query = query.join(relationTable, localId, foreignId);
134+
joinedTables.push(relationPath.join('.'));
135+
} else {
136+
// local column
137+
}
134138
}
135139
localResourceConfig = relationResourceConfig;
136140
};
@@ -471,25 +475,25 @@ module.exports =
471475
/* 1 */
472476
/***/ function(module, exports) {
473477

474-
module.exports = require("knex");
478+
module.exports = require("mout/string/underscore");
475479

476480
/***/ },
477481
/* 2 */
478482
/***/ function(module, exports) {
479483

480-
module.exports = require("js-data");
484+
module.exports = require("knex");
481485

482486
/***/ },
483487
/* 3 */
484488
/***/ function(module, exports) {
485489

486-
module.exports = require("mout/array/map");
490+
module.exports = require("js-data");
487491

488492
/***/ },
489493
/* 4 */
490494
/***/ function(module, exports) {
491495

492-
module.exports = require("mout/string/underscore");
496+
module.exports = require("mout/array/map");
493497

494498
/***/ },
495499
/* 5 */

mocha.start.js

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -58,8 +58,9 @@ beforeEach(function () {
5858
adapter = new DSSqlAdapter({
5959
client: 'mysql',
6060
connection: {
61-
user: process.env.C9_USER || 'ubuntu',
62-
database: process.env.C9_USER ? 'c9' : 'circle_test'
61+
host: process.env.DB_HOST || 'localhost',
62+
user: process.env.DB_USER || process.env.C9_USER || 'ubuntu',
63+
database: process.env.DB_NAME || (process.env.C9_USER ? 'c9' : 'circle_test')
6364
//user: 'root',
6465
//database: 'test'
6566
}

package.json

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
{
22
"name": "js-data-sql",
33
"description": "Postgres/MySQL/MariaDB/SQLite3 adapter for js-data.",
4-
"version": "0.11.2",
4+
"version": "0.11.3",
55
"homepage": "http://www.js-data.io/docs/dssqladapter",
66
"repository": {
77
"type": "git",
@@ -40,7 +40,7 @@
4040
"scripts": {
4141
"lint": "node_modules/standard/bin/cmd.js src/index.js",
4242
"build": "node_modules/webpack/bin/webpack.js --config webpack.config.js --progress --colors",
43-
"mocha": "mocha test/*.spec.js --timeout 20000 --reporter spec",
43+
"mocha": "mocha --timeout 20000 --reporter spec mocha.start.js test/*.spec.js",
4444
"test": "npm run lint && npm run build && npm run mocha"
4545
},
4646
"standard": {

src/index.js

Lines changed: 10 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -65,14 +65,18 @@ function filterQuery (resourceConfig, params, options) {
6565

6666
if (!joinedTables.some(t => t === relationPath.join('.'))) {
6767
let [relation] = localResourceConfig.relationList.filter(r => r.relation === relationName)
68-
let table = getTable(localResourceConfig)
69-
let localId = `${table}.${relation.localKey}`
68+
if (relation) {
69+
let table = getTable(localResourceConfig)
70+
let localId = `${table}.${relation.localKey}`
7071

71-
let relationTable = getTable(relationResourceConfig)
72-
let foreignId = `${relationTable}.${relationResourceConfig.idAttribute}`
72+
let relationTable = getTable(relationResourceConfig)
73+
let foreignId = `${relationTable}.${relationResourceConfig.idAttribute}`
7374

74-
query = query.join(relationTable, localId, foreignId)
75-
joinedTables.push(relationPath.join('.'))
75+
query = query.join(relationTable, localId, foreignId)
76+
joinedTables.push(relationPath.join('.'))
77+
} else {
78+
// local column
79+
}
7680
}
7781
localResourceConfig = relationResourceConfig
7882
}

test/findAll.spec.js

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -182,4 +182,14 @@ describe('DSSqlAdapter#findAll', function () {
182182
assert.isUndefined(users[0].email);
183183
});
184184

185+
it('should filter when relations have same column if column is qualified', function* () {
186+
var profile1 = yield adapter.create(Profile, { email: '[email protected]' });
187+
var user1 = yield adapter.create(User, {name: 'John', profileId: profile1.id});
188+
189+
// `id` column must be qualified with `user.`
190+
var users = yield adapter.findAll(User, {'user.id': user1.id, 'profile.email': '[email protected]'});
191+
assert.equal(users.length, 1);
192+
assert.equal(users[0].profileId, profile1.id);
193+
});
194+
185195
});

0 commit comments

Comments
 (0)