contao/import — Issue #3638: Inconsistent behaviour in DC_Table 2.10.3
Author: Toflar
Created: 2011-11-29 21:54:25+00:00
State: open
Labels: backend, Defect

Hi Leo

I discovered an inconsistency in DC_Table in 2.10.3 as we can now use Controller::eliminateNestedPages() with sorting.

```
// Get the IDs of all root records (tree view)
if ($this->treeView)
{
$table = ($GLOBALS['TL_DCA'][$this->strTable]['list']['sorting']['mode'] == 6) ? $this->ptable : $this->strTable;

// Unless there are any root records specified, use all records with parent ID 0
if (!isset($GLOBALS['TL_DCA'][$table]['list']['sorting']['root']) || $GLOBALS['TL_DCA'][$table]['list']['sorting']['root'] === false)
{
$objIds = $this->Database->prepare("SELECT id FROM " . $table . " WHERE pid=?" . ($this->Database->fieldExists('sorting', $strTable) ? ' ORDER BY sorting' : ''))
->execute(0);

if ($objIds->numRows > 0)
{
$this->root = $objIds->fetchEach('id');
}
}

// Get root records from global configuration file
elseif (is_array($GLOBALS['TL_DCA'][$table]['list']['sorting']['root']))
{
$this->root = $this->eliminateNestedPages($GLOBALS['TL_DCA'][$table]['list']['sorting']['root'], $table, true);
}
}
```

If I do not set any sorting->root, then the root array consists of all id's of that table and "ORDER BY sorting" is only applied when "sorting" exists as a column in the database.
But if I do set sorting->root then it does now automatically sort by "sorting" because of the third parameter that is set to "true".

I don't know whether you want to force having a "sorting" column in a tree view or not but in my opinion you should be consistent. Either it has to be there or not =)

I attached a patch for a solution that would respect the behaviour we had up to 2.10.2 ;)

[Download the attachments](http://www.contao.org/tl_files/tickets/3638.zip "Download the attachments of this ticket")

--- _Originally created on November 16th, 2011, at 09:41am (ID 3638)_