Question: how to get number of related records

Status
Not open for further replies.

troester

Administrator
Staff member
How can I access the number of related records in a canDeleteRow plugin (it's not in $data or $row)?
Related data (list) is activated and shown in list view.

(Record should be only deletable if there are no related records)
 
try this, it should give you an array the total related records

PHP:
// The id of the database join element in the related list
$elementid = 1;
$elementModel = JModelLegacy::getInstance('Element', 'FabrikFEModel');
$element = $elementModel->getElement();
 
// array  of counts key'd on element's primary key
$counts = $this->getRecordCounts($element, $ids);
 
Hmm, didn't get it working with your code.
It's in canDeleteRow (not list php).

I've managed it by fetching it directly from the DB (SELECT count(*) from related-table WHERE dbjoin-element = $rowid)
but I've thought the value is already "somewhere" as it is displayed in list view.
 
It wouldn't be loaded in canDeleteRow as its an overhead that isn't usually needed.
 
Status
Not open for further replies.
We are in need of some funding.
More details.

Thank you.

Members online

No members online now.
Back
Top