delete only record in associated models

livingwebstudio 06 Jan, 2016
Hi,
I have a connection with principal model and 2 related models with "hasMany" relation type.
It's possible to delete and add a single record in the related models?
this is the example:
first model: DRAFT
second model: AUTHORS
third model: IMAGES
the draft has many authors and images; how can I delete one of this authors or images?
GreyHead 06 Jan, 2016
Hi livingwebstudio,

I assume that the Authors and Images are not uniquely linked to the parent Draft record - if so then you could do this with a custom form event. Pass the ID of the record to be deleted and use a Custom Code action to do the deletion.

Bob
livingwebstudio 06 Jan, 2016
what kind of custom code can delete the row in my db table?
GreyHead 08 Jan, 2016
Hi livingwebstudio,

<?php
$db = \JFactory::getDBO();
$query = "
    DELETE FROM `#__` WHERE `column_name` = '{$form->data['input_name']}' ;
";
$db->setQuery($query);
$db->execute();
?>

Bob
This topic is locked and no more replies can be posted.