How can we use BeforeDelete targeting another module

i have new module with yii who have to check any delete actions to other module how can i use BeforeDelete in my new module targeting any update in another module ? thank you

Hi @hazmaniameur, welcome to the forum.

Could you please elaborate your question a little further?

So you have module A and module B. And you want to do something in module A when something is deleted in module B. Am I right?

  1. What do you want to delete in module B?
  2. What do you want to do in module A? Is it related to the deleted object in phase 1?

Hi @softark thank you for your answer,
i have first module named ** Search ** who is is using ElasticSearch (search engine)
and i have a module named ** Posts **, whois in charge to manage posts made by different users.
** without modifing the module Posts **, i whould like to listen to any action delete who is targeting the tables of Posts module **, from the module Search ** module, to ask this module to delete them also from ElasticSearch.

to simply answer to your questions :

  1. want to delete records from ElasticSearch when those are deleted from the mysql database
  2. Listen to any deleteed action in his table FROM the module B, and no there is no releted object ok forgein_keys

thank you for your help :blush:

Thank you, I think I understand your requirements.
I would do the following if I were you.

  1. In Post ActiveRecord model, I would customize beforeDelete method to call some static method of Search model.
  2. In Search model, I would write some static method that would delete certain entries based on the parameters of the method.
  3. The parameters could be a string (text), an array of strings (key words), or, maybe the Post model itself. I’m not really sure about this point. It depends.

Note that ActiveRecord::deleteAll() method won’t trigger beforeDelete(). Please check the following section of the guide:

You can not catch a delete action of Post in Search model.