[eluser]OverZealous[/eluser]
[quote author="Mirage" date="1251419600"]Suggestions?[/quote]
Why don't you simply replace node with {$node->table}. Then you don't have to add it to the FROM list. You can also use more of the DMZ functions this way:
Code:
function get_children($node) {
// get children by getting descendants with count and limit that to 1
// De-reference some vars for readability
$lcol = $this->options['left_colname'];
$rcol = $this->options['right_colname'];
// only add selections if not overridden
if(empty($node->db->ar_select))
{
$node->select('*');
}
else
{
// ensure these are selected
$node->select("id, $lcol, $rcol");
}
// DMZ won't add the table name to expressions with parentheses
$node->select('(COUNT(parent.id)-1) as tree_depth');
// Isolate the dependants of the parent which are 1 level away
$node->db->from("{$node->table} as parent");
// Only descendants, parent node not included
$node->where("{$lcol} >", "parent.{$lcol}", FALSE);
$node->where("{$lcol} <", "parent.{$rcol}", FALSE);
// Only for the parents part of the tree
$node->where("{$lcol} >", $node->$lcol);
$node->where("{$rcol} <", $node->$rcol);
$node->group_by("id");
$node->having("tree_depth =",1); // DMZ won't add the table name to unknown columns
$node->order_by($lcol);
// Run query
$node->get();
}
This also allows someone to add query information to the result, such as writing code like this: