diff --git a/lib/ormish.js b/lib/ormish.js index d05f5a9..b8975dc 100644 --- a/lib/ormish.js +++ b/lib/ormish.js @@ -244,22 +244,26 @@ export class Model { } /* - Delete this object from the database. It uses this object's `.id` to determine - which object to delete and uses this `knex` code: + Delete this object from the database. We use the word "destroy" because + `delete` is reserved. It uses this object's `.id` to determine which object + to delete and uses this `knex` code: ```javascript - await knex(this.table_name).where({id: this.id}).del(); + await knex(obj.table_name).where({id: obj.id}).del(); ``` As with all of ORMish it doesn't handle any relations or references when it does the delete so if you have constraints it will fail. Use `knex` directly in that case. + + + `obj Model` -- the object to destroy, just have id */ - async destroy() { + static async destroy(obj) { assert(this.table_name !== undefined, "You must set class variable table_name."); + assert(obj.id !== undefined, "No id in object to destroy."); await knex(this.table_name). - where({id: this.id}). + where({id: obj.id}). del(); }