AnsweredAssumed Answered

Sugar (relationship) delete logic error (inconsistency)

Question asked by BlueDhampir BlueDhampir on Jul 24, 2014
Latest reply on Aug 26, 2014 by BlueDhampir BlueDhampir
Hello All,

IMHO, data/link.php, delete() inconsistently deletes relationship data, because it irreversibly updates parent_id
field (sets it to null). Here is the description of the aforementioned function:

/* this method operates on all related record, takes action based on cardinality of the relationship. 
 * one-to-one, one-to-many: update the rhs table's parent id with null 
 * many-to-one: update the lhs table's parent-id with null. 
 * many-to-many: 
delete rows from the link table. related table must have delted and date_modified column. 
 * if related_is is null, the methods assumes that the parent bean (whose id is passed) is being deleted. 
 * if both id and related_id are passed the metod unlinks a single relationship. 
 * parameters: id of the bean being deleted. 
 *      
 */  

Now consider a real situation, then the user deletes some particular email (which of course has the attachments, i.e. notes).
This action (delete email), marks email record as deleted and/but irreversibly updates notes.parent_id field to NULL, so after all (some time) we have a whole bunch of ghosted/lost notes in the database, and second, that is very important, IMHO, we are no longer able to undelete email completely/correctly. I think, that in such situation related records should also be marked as deleted, but not unrelated completely and irreversibly.


Version 6.5.11 (Build 8754) CE

Thanks,

Outcomes