修复update的时候因为误删了id字段导致不能关联更新的bug

This commit is contained in:
akira_cn 2015-12-05 00:47:00 +08:00
parent 3e7125444f
commit ba781ecbbd

View File

@ -276,18 +276,6 @@ export default class extends Base {
options = await this.parseOptions(options);
//check where condition
if(think.isEmpty(options.where)){
//get where condition from data
let pk = await this.getPk();
if(data[pk]){
options.where = {[pk]: data[pk]};
delete data[pk];
}else {
return think.reject(new Error(think.locale('MISS_WHERE_CONDITION')));
}
}
//remove readonly field data
this.readonlyFields.forEach(item => {
delete data[item];
@ -297,9 +285,21 @@ export default class extends Base {
return think.reject(new Error(think.locale('DATA_EMPTY')));
}
data = this.parseData(data);
data = await this.beforeUpdate(data, options);
let rows = await this.db().update(data, options);
let parsedData = this.parseData(data);
//check where condition
if(think.isEmpty(options.where)){
//get where condition from data
let pk = await this.getPk();
if(parsedData[pk]){
options.where = {[pk]: parsedData[pk]};
delete parsedData[pk];
}else {
return think.reject(new Error(think.locale('MISS_WHERE_CONDITION')));
}
}
parsedData = await this.beforeUpdate(parsedData, options);
let rows = await this.db().update(parsedData, options);
await this.afterUpdate(data, options);
return rows;
}