SOLVED: Update field value on delete/update of a row on same table

dimoss

Well-Known Member
Hi,

I have one list where I use two fields ('ui', 'dr') to create pairs.
For example in two records I can make the pair as follows:

Record 1: ui = M1, dr = M2
Record 2: ui = M2, dr = M1

What I want to achieve is whenever I delete a record to have a query to run and look for the 'ui' value on 'dr' field and make it NULL

In the above example if I delete Record 2 then in Record 1 the 'dr' value should be updated to NULL

The same also when I update Record 2 changing 'dr' value having a query to run and look for 'dr' value on 'ui' field and make the 'dr' value on Record 1 = NULL

Thanks
 
You can use two php form plugins (onDeleteRow and onAfterProcess) for selecting and modifying the other records.
 
You can use two php form plugins (onDeleteRow and onAfterProcess) for selecting and modifying the other records.
Hi Troester

Thanks for the reply.
If the deletion done from the list I should use php_events plugin OnDeleteRows?
 
Hi Troester,

I tried the following using the php_events plugin OnDeleteRows to grab the rowid:
Code:
$data = $model->getData();
foreach ($data[0][0] as $row){
$rowid = $row->fab_accom_ittf___id;
}

However it returns NULL when I tried to var_dump it.
 
Finally manage to do the deletion through OnDeleteRows using the following:

Code:
$app = JFactory::getApplication();
$ids = $app->input->get('ids', array(), 'array');
foreach ($ids AS $myid)
{
    $row = $model->getRow($myid);
    $element_raw = $row->fab_accom_ittf___ui_raw;
}
$db = JFactory::getDBO();
$query = "UPDATE fab_accom_ittf SET dr_with = NULL WHERE dr_with = ".$db->quote($element_raw);
$db->setQuery( $query );
$db->execute();

I will do something similar using php form plugin for the update.
 
Last edited:
We are in need of some funding.
More details.

Thank you.

Members online

Back
Top