联合查询的另一种实现方式—利用数组

let itemKey = 0;
for (const addressItem of addressList) {
addressList[itemKey].province_name = await this.model('region').getRegionName(addressItem.province_id);
addressList[itemKey].city_name = await this.model('region').getRegionName(addressItem.city_id);
addressList[itemKey].district_name = await this.model('region').getRegionName(addressItem.district_id);
addressList[itemKey].full_region = addressList[itemKey].province_name + addressList[itemKey].city_name + addressList[itemKey].district_name;
itemKey += 1;
}

return this.success(addressList);


针对数组,这里采用的办法是可以取代联合查询的。这里涉及了两个表address以及region,对于model层的region进行操作。其中:
getRegionName(regionId) {
var _this3 = this;

return _asyncToGenerator(function* () {
return _this3.where({ id: regionId }).getField('name', true);
})();
}
说白了,通过对数组进行改装,从而实现,联合的查询

原文地址:https://www.cnblogs.com/superAnny/p/8422034.html