delete method

Future<bool> delete()
inherited

Delete the model from the database.

Implementation

Future<bool> delete() async {
  if (!exists) return false;

  if (this is HasEvents) {
    if (await (this as HasEvents).fireModelEvent(ModelLifecycle.deleting) ==
        false) {
      return false;
    }
  }

  await query.where(primaryKey, '=', getKey()).delete();

  if (this is HasEvents) {
    await (this as HasEvents)
        .fireModelEvent(ModelLifecycle.deleted, halt: false);
  }

  exists = false;
  return true;
}