From Joomla! Documentation

< API16:JTable

The "API16" namespace is an archived namespace. This page contains information for a Joomla! version which is no longer supported. It exists only as a historical reference, it will not be improved and its content may be incomplete and/or contain broken links.


Generic check for whether dependancies exist for this object in the database schema


canDelete($pk=null, $joins=null)
Parameter Name Default Value Description
$pk null An optional primary key value check the row for. If not set the instance property value is used.
$joins null An optional array to compiles standard joins formatted like: [label => 'Label', name => 'table name' , idfield => 'field', joinfield => 'field']


boolean True on success.

Defined in



jimport( 'joomla.database.table' );

Source Body

public function canDelete($pk = null, $joins = null)
        // Initialise variables.
        $k = $this->_tbl_key;
        $pk = (is_null($pk)) ? $this->$k : $pk;

        // If no primary key is given, return false.
        if ($pk === null) {
                return false;

        if (is_array($joins)) {
                // Get a query object.
                $query  = $this->_db->getQuery(true);

                // Setup the basic query.
                $query->where('`'.$this->_tbl_key.'` = '.$this->_db->quote($this->$k));

                // For each join add the select and join clauses to the query object.
                foreach($joins as $table) {
                        $query->select('COUNT(DISTINCT '.$table['idfield'].') AS '.$table['idfield']);
                        $query->join('LEFT', $table['name'].' ON '.$table['joinfield'].' = '.$k);

                // Get the row object from the query.
                $this->_db->setQuery((string) $query, 0, 1);
                $row = $this->_db->loadObject();

                // Check for a database error.
                if ($this->_db->getErrorNum()) {
                        return false;

                $msg = array();
                $i = 0;
                foreach($joins as $table) {
                        $k = $table['idfield'] . $i;
                        if ($obj->$k) {
                                $msg[] = JText::_($table['label']);

                if (count($msg)) {
                        $this->setError("noDeleteRecord" . ": " . implode(', ', $msg));
                        return false;
                } else {
                        return true;

        return true;


Code Examples