@ -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 ( ) ;
}
}