From d1601cc910f2840821b22effce7c4e1c2d0cd889 Mon Sep 17 00:00:00 2001 From: lichengyin Date: Wed, 23 Mar 2016 17:22:05 +0800 Subject: [PATCH] Fix can not change key & fKey when relation type is belong to --- src/model/relation.js | 6 ++++-- 1 file changed, 4 insertions(+), 2 deletions(-) diff --git a/src/model/relation.js b/src/model/relation.js index 661e9748..7f9ba55e 100644 --- a/src/model/relation.js +++ b/src/model/relation.js @@ -155,6 +155,10 @@ export default class extends think.model.base { switch(item.type){ case think.model.BELONG_TO: + opts = think.extend(opts, { + key: opts.model.getModelName() + '_id', + fKey: 'id' + }, item); return this._getBelongsToRelation(data, opts, options); case think.model.HAS_MANY: return this._getHasManyRelation(data, opts, options); @@ -188,8 +192,6 @@ export default class extends think.model.base { * @return {Promise} [] */ async _getBelongsToRelation(data, mapOpts/*, options*/){ - mapOpts.key = mapOpts.model.getModelName() + '_id'; - mapOpts.fKey = await mapOpts.model.getPk(); let where = this.parseRelationWhere(data, mapOpts); let mapData = await mapOpts.model.where(where).select(); return this.parseRelationData(data, mapData, mapOpts);