From ccff00a3d68514d0045898ada72fab5c93a6325d Mon Sep 17 00:00:00 2001 From: welefen Date: Thu, 23 Jul 2015 16:42:48 +0800 Subject: [PATCH] rename this.model in rest controller --- src/controller/rest.js | 20 ++++++++++---------- 1 file changed, 10 insertions(+), 10 deletions(-) diff --git a/src/controller/rest.js b/src/controller/rest.js index 8751f7e6..9c0c179d 100644 --- a/src/controller/rest.js +++ b/src/controller/rest.js @@ -13,7 +13,7 @@ export default class extends think.controller.base { super.init(http); this.resource = this.get('resource'); this.id = this.get('id') | 0; - this.model = this.model(this.resource); + this.modelInstance = this.model(this.resource); } /** * get resource @@ -22,11 +22,11 @@ export default class extends think.controller.base { async getAction(){ let data; if (this.id) { - let pk = await this.model.getPk(); - data = await this.model.where({[pk]: this.id}).find(); + let pk = await this.modelInstance.getPk(); + data = await this.modelInstance.where({[pk]: this.id}).find(); return this.success(data); } - data = await this.model.select(); + data = await this.modelInstance.select(); return this.success(data); } /** @@ -34,13 +34,13 @@ export default class extends think.controller.base { * @return {Promise} [] */ async postAction(){ - let pk = await this.model.getPk(); + let pk = await this.modelInstance.getPk(); let data = this.post(); delete data[pk]; if(think.isEmpty(data)){ return this.fail('data is empty'); } - let insertId = await this.model.add(data); + let insertId = await this.modelInstance.add(data); return this.success({id: insertId}); } /** @@ -51,8 +51,8 @@ export default class extends think.controller.base { if (!this.id) { return this.fail('params error'); } - let pk = await this.model.getPk(); - let rows = await this.model.where({[pk]: this.id}).delete(); + let pk = await this.modelInstance.getPk(); + let rows = await this.modelInstance.where({[pk]: this.id}).delete(); return this.success({affectedRows: rows}); } /** @@ -63,13 +63,13 @@ export default class extends think.controller.base { if (!this.id) { return this.fail('params error'); } - let pk = await this.model.getPk(); + let pk = await this.modelInstance.getPk(); let data = this.post(); delete data[pk]; if (think.isEmpty(data)) { return this.fail('data is empty'); } - let rows = await this.model.where({[pk]: this.id}).update(data); + let rows = await this.modelInstance.where({[pk]: this.id}).update(data); return this.success({affectedRows: rows}); } /**