/**
* Assert that the nested set data is valid.
*
* @return boolean True if the instance is sane and able to be stored in the database.
*
* @since 1.7.0
*/
public function check()
{
try {
parent::check();
} catch (\Exception $e) {
$this->setError($e->getMessage());
return false;
}
$this->parent_id = (int) $this->parent_id;
if (empty($this->rules)) {
$this->rules = '{}';
}
// Nested does not allow parent_id = 0, override this.
if ($this->parent_id > 0) {
// Get the DatabaseQuery object
$query = $this->_db->getQuery(true)->select('1')->from($this->_db->quoteName($this->_tbl))->where($this->_db->quoteName('id') . ' = ' . $this->parent_id);
$query->setLimit(1);
if ($this->_db->setQuery($query)->loadResult()) {
return true;
}
$this->setError(Text::_('JLIB_DATABASE_ERROR_INVALID_PARENT_ID'));
return false;
}
return true;
}