Related table rows was deleted

Good day. I am using v7.10.10.

I have these modules region, city, province, and country that is related to my module prospect_inquiry.
I have no custom codes or whatsoever that enables to delete or update a row in any table.

At first, when I checked the database, I found out that there were some rows that has been deleted in the related modules (region, city, province, country), i thought that maybe I just deleted it by accident so I manually updated them in the database. I changed the deleted column to 0. But when I checked it the day after, some of the rows has been deleted again. I haven’t done anything since I updated it manually. So, I manually changed them again, but the issue keeps repeating. I don’t have any ideas what events that trigger this issue.

Please help me. Please feel free to ask any question regarding to this topic. Thank you :slight_smile:

There is a scheduler job (Prune database on 1st of month) that permanently deletes records marked with “deleted=1”. This job is disable by default. But if I understood correctly, this is not your case. What you have is records that have “deleted=0” and then show up with “deleted=1”, am I correct?

Do you have any Workflow or Logic Hooks that might be doing this?

You are correct. I have a logic hook (before_save) but the only thing it does is add a value to the $bean->name. It doesn’t contain any updates connecting with the delete column. And second thing, I haven’t encountered workflow so I believe that is not the case.

I understand your logic hook shouldn’t be having any effect on “deleted” field, but still, as a diagnostic, can you try disabling the logic hook to see if the problem persists?

I accidentally found what event updates the status of column deleted in related tables to 1. It is when I create a new record. I tried disabling my logic hook as you have suggested but the issue still remains. I’m going nuts right now. haha

Another thing, if I add a record that has a city with value “New York City”, all records from the table city having the same value will be deleted.

It shouldn’t be too difficult to trace where that is coming from.

Re-check your Workflows for anything on record creation, or “all records”.

Then re-check all you logic hooks. It might be easier to check the consolidated files here:


but if you need to change anything, you don’t change it there - you find the original file under custom/Extension.

I checked everything you have said. In workflows, I don’t have anything created in it.
In logic_hooks, there are not much codes that I have been doing, but then as you suggested, I checked and it seems fine. I tried disabling them too and the issue remains.

This is surely not something that is standard SuiteCRM behaviour:

That MUST be coming from your custom code. Unless your disk or your database are playing weird tricks on you, in which case they will probably just fail completely VERY soon.

What is the story in your company? Did anyone customize SuiteCRM there before you came along? Can you reach them?

I was the one who took over the project. Anyway, I have a suspicion, is this maybe because the relationship is one to one?

SuiteCRM does not do “cascading” deletes on relationships. Sometimes this is even a problem; but since different companies have different requirements, the more conservative option was taken, don’t delete stuff behind the scenes, let each company do it according to their own requirements.

So no, I don’t think that SuiteCRM is doing those deletes. I would really look for custom code. As I said, this should be either in logic hooks, or Workflows. But it’s possible to make other arrangements: override classes, for example.

You need to thoroughly go through everything you have in the custom directory. But it’s also possible that whoever did that, did not follow best-practices, and made customizations that are not upgrade-safe, so they might be mixed up in the middle of the code, in other directories, and they can be hard to track down.

I suggest you either set up an IDE and a debugger (with XDEBUG) and step through the cde to see where the delete is happening; or raise the log level to DEBUG (in Admin / System settings) and try to see the query generated, or other elements that you can use to search the code. Good luck…