Crazy weird bug in ormish.js because I...never destroyed anything? Not sure why but I didn't actually ever run Model.destroy, and it turns out that it should be static like the other methods but I missed that.

main
Zed A. Shaw 2 years ago
parent 7ce284680c
commit bc6924ffea
  1. 14
      lib/ormish.js

@ -244,22 +244,26 @@ export class Model {
} }
/* /*
Delete this object from the database. It uses this object's `.id` to determine Delete this object from the database. We use the word "destroy" because
which object to delete and uses this `knex` code: `delete` is reserved. It uses this object's `.id` to determine which object
to delete and uses this `knex` code:
```javascript ```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 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 the delete so if you have constraints it will fail. Use `knex` directly in that
case. 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(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). await knex(this.table_name).
where({id: this.id}). where({id: obj.id}).
del(); del();
} }

Loading…
Cancel
Save