Core: How to enable softDeletes

Created on 21 Oct 2016  路  4Comments  路  Source: adonisjs/core

Hey, this is the first time i am raising a query to github. I am new to AdonisJs and currently i am having troubles with softDeletes. I followed the documentation but still no luck with softDeletes.
This is what i did in my Model :

'use strict'

const Lucid = use('Lucid')

class Note extends Lucid {

static get deleteTimestamp () {
    var note = new Note();
    return note.deleted_at;
  }

//And i event tried writing the above code like this:

static get deleteTimestamp () {
    return this.deleted_at;
  }

/*This is my Function to delete the row in the same Model Class*/

*deleteNote(id){

    var i;
    for(i=0;i<id.length;i++){

      var notes = yield Note.findBy('id',id[i]);
      yield notes.delete();

    }

    return "Notes Deleted Successfully"

  }

I've also added table.softDeletes() in my Migrations and after running the migrations it successfully created the column deleted_at in the table of my database

When i deletes a row by calling *deleteNote() from my Controller..it completely deletes the row instead of updating deleted_at column of the database.

Please help to this as i don't get how we can enable it... 馃槩

Most helpful comment

I believe it should be like that

static get deleteTimestamp () {
    return 'deleted_at'
}

All 4 comments

I believe it should be like that

static get deleteTimestamp () {
    return 'deleted_at'
}

Wow...it worked like a charm....thanksss a lot man..you saved my time 馃憤 馃槅

Jst Loved it!!!! 馃挴 馃槅

@PC-HUB you are welcome bro... Happy coding :smile:

This thread has been automatically locked since there has not been any recent activity after it was closed. Please open a new issue for related bugs.

Was this page helpful?
0 / 5 - 0 ratings

Related issues

themodernpk picture themodernpk  路  3Comments

devcaststudio picture devcaststudio  路  3Comments

douglaszaltron picture douglaszaltron  路  3Comments

codingphasedotcom picture codingphasedotcom  路  3Comments

seanc picture seanc  路  4Comments