Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

How to implement logical delete (SoftDelete) in ActiveJDBC? #1009

Closed
logue opened this issue Mar 23, 2020 · 3 comments
Closed

How to implement logical delete (SoftDelete) in ActiveJDBC? #1009

logue opened this issue Mar 23, 2020 · 3 comments

Comments

@logue
Copy link

logue commented Mar 23, 2020

How do I implement a logical delete that flags a record for deletion, rather than physically deleting the record from the table, like Eloquent's SoftDelete trait?

If implemented normally, the validator defined in the model will running.

@ipolevoy
Copy link
Member

ipolevoy commented Mar 23, 2020

We do not have this feature in the framework directly. However, it does not seem hard to implement at the application level, for instance:

  1. Add column deleted_at to PEOPLE table

  2. Write a model class:

class Person extends Model{

   boolean isDeleted(){
       return get("deleted_at") != null;
   }

   void delete(){
       set("deleted_at", new Date());
       saveIt();
    }
}

after that, add this to other queries: "...where deleted_at is NULL"

as you can see, not that hard. However, adding this feature directly to the framework is a good idea.

@logue
Copy link
Author

logue commented Mar 24, 2020

It went well.
Thank you very much.

Since it is a boolean type, exactly isn't it.

public boolean delete() {
    set("deleted_at", new Date());
    return save();
}

@ipolevoy
Copy link
Member

sure, this works. Just keep in mind that save() and saveIt() are not the same.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

No branches or pull requests

2 participants