Hi again,
No way to have the "addRoot" function working.
This is the query in my case:
$columns = array('id','el_ref','parent_id', 'lft', 'rgt','level','title','alias','access');
$db2 = JFactory::getDbo();
$query_add = $db2->getQuery(true);
$values = array(1, $db2->quote('system'), 0, 0, 1, 0, $db2->quote('root'), $db2->quote('root'), 1);
$query_add
->insert($db2->quoteName('#__manta_elements'))
->columns($db2->quoteName($columns))
/*->values("'0','0','1','0','{$db->quote('root')}','{$db->quote('root')}','1','{$db->quote('')}'");*/
->values(implode(',', $values));
$db2->setQuery($query_add);
try {
$apply = $db2->query_add(); // $db->execute(); for Joomla 3.0.
} catch (Exception $e) {
// catch the error.
}
$query_add->clear();
The query is correct, I checked it separately.
When I evaluate the existence of the root element inside the "prepareTable" function, I would like, in case of non-existence, to have the root node created before I save my element. Anyhow, either if call the addRoot function or if I directly insert it inside my if statement, I can't have the root node created.
I do not receive any error message, simply the first query is not executed and then the second one fails becaues the parent_id (which is the root id) is not correct (this is obvious, since the root element has not been created).
Can anyone suggest where I should call the root test and query so to have it executed before the element is saved? Clearly the "prepareTable" function is not the right place...
So far, the only workaround that I can think about is to create the root element via sql when the database is created. But I would like to know anyhow how I could have the addRoot function working.
Thanks for any possible suggestion.
Elena