think-model
Advanced tools
Comparing version 1.5.3 to 1.5.4
@@ -19,4 +19,5 @@ const helper = require('think-helper'); | ||
* parse where in relation model | ||
* @param {String} prefix prefix for table alia name | ||
*/ | ||
parseRelationWhere() { | ||
parseRelationWhere(prefix = '') { | ||
const { key, fKey } = this.options; | ||
@@ -33,3 +34,3 @@ if (helper.isArray(this.data)) { | ||
return { | ||
[fKey]: ['IN', keys] | ||
[prefix + fKey]: ['IN', keys] | ||
}; | ||
@@ -39,3 +40,3 @@ } | ||
return { | ||
[fKey]: this.data[key] | ||
[prefix + fKey]: this.data[key] | ||
}; | ||
@@ -42,0 +43,0 @@ } |
@@ -23,3 +23,3 @@ function _asyncToGenerator(fn) { return function () { var gen = fn.apply(this, arguments); return new Promise(function (resolve, reject) { function step(key, arg) { try { var info = gen[key](arg); var value = info.value; } catch (error) { reject(error); return; } if (info.done) { resolve(value); } else { return Promise.resolve(value).then(function (value) { step("next", value); }, function (err) { step("throw", err); }); } } return step("next"); }); }; } | ||
return _asyncToGenerator(function* () { | ||
const where = _this.parseRelationWhere(); | ||
const where = _this.parseRelationWhere('b.'); | ||
if (where === false) return _this.data; | ||
@@ -26,0 +26,0 @@ const relationModel = _this.options.rModel || _this.getRelationModelName(); |
{ | ||
"name": "think-model", | ||
"version": "1.5.3", | ||
"version": "1.5.4", | ||
"description": "An adapter-based ORM for ThinkJS 3.x", | ||
@@ -5,0 +5,0 @@ "scripts": { |
@@ -65,3 +65,3 @@ const {test} = require('ava'); | ||
relation.options.model.select = function() { | ||
t.deepEqual(this.options, {'field': '*,b.post_id', 'fieldReverse': false, 'alias': 'a', 'where': {'post_id': ['IN', [3, 10]]}, 'join': [{'post_user': {'table': 'relationModel', 'as': 'b', 'join': 'inner', 'on': ['id', 'user_id']}}]}); | ||
t.deepEqual(this.options, {'field': '*,b.post_id', 'fieldReverse': false, 'alias': 'a', 'where': {'b.post_id': ['IN', [3, 10]]}, 'join': [{'post_user': {'table': 'relationModel', 'as': 'b', 'join': 'inner', 'on': ['id', 'user_id']}}]}); | ||
return [ | ||
@@ -68,0 +68,0 @@ {name: 'lizheming', post_id: 10}, |
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
118287
4018