Search code examples
activejdbc

Detect models deletion


I have a working SQLite database with ActiveJDBC. I would like to perform some operation when I detect that a model is being deleted (either through direct deletion, or as a result of a cascade delete). I can detect direct deletions by overriding the delete() method in my models. Is it possible to detect the other model deletions?

In addition, I found a somewhat strage behavior. If a model is deleted as a result of a cascade operation, it is not frozen in the process, so I can still work with it even when the database does not store it any longer. Is this supposed to be the expected behavior?

Regards.

PS: I cannot use the javalite tag, as it does not exist and I cannot create new tags.


Solution

  • @alberto-anguita, please see Life Cycle callbacks: http://javalite.io/lifecycle_callbacks, specifically these callbacks:

    void beforeDelete(); void afterDelete();

    They will allow you to get notified if your model is deleted.

    If a model is deleted as a result of a cascade, and not marked frozen, this might be an issue. Please, submit and document it here: https://github.com/javalite/activejdbc/issues. Specify exactly what cascade method you are using. Defects like that usually takes less than 24 hours to fix.

    You cannot create a javalite tag because your reputation on SO is 1 :)