Skip to content

Commit

Permalink
Merge pull request #86 from Fooriva/4.0
Browse files Browse the repository at this point in the history
Fix select table.* columns order
  • Loading branch information
moufmouf committed Apr 27, 2016
2 parents 9dcf2a5 + 6bab21f commit 342c0a3
Showing 1 changed file with 18 additions and 16 deletions.
34 changes: 18 additions & 16 deletions src/Mouf/Database/TDBM/TDBMService.php
Expand Up @@ -1337,24 +1337,26 @@ public function findObjectsFromSql($mainTable, $from, $filter = null, array $par

$allFetchedTables = $this->_getRelatedTablesByInheritance($mainTable);

$sql = 'SELECT DISTINCT '.$this->connection->quoteIdentifier($mainTable).'.* FROM '.$from;
$columnDescList = [];
$schema = $this->tdbmSchemaAnalyzer->getSchema();
$tableGroupName = $this->getTableGroupName($allFetchedTables);

if (count($allFetchedTables) === 1) {
$columnDescList = [];
$schema = $this->tdbmSchemaAnalyzer->getSchema();
$tableGroupName = $this->getTableGroupName($allFetchedTables);
foreach ($schema->getTable($mainTable)->getColumns() as $column) {
$columnName = $column->getName();
$columnDescList[] = [
'as' => $columnName,
'table' => $mainTable,
'column' => $columnName,
'type' => $column->getType(),
'tableGroup' => $tableGroupName,
];
}

foreach ($schema->getTable($mainTable)->getColumns() as $column) {
$columnName = $column->getName();
$columnDescList[] = [
'as' => $columnName,
'table' => $mainTable,
'column' => $columnName,
'type' => $column->getType(),
'tableGroup' => $tableGroupName,
];
}
} else {
$sql = 'SELECT DISTINCT '.implode(', ', array_map(function($columnDesc) use ($mainTable) {
return $this->connection->quoteIdentifier($mainTable).'.'.$this->connection->quoteIdentifier($columnDesc['column']);
}, $columnDescList)) .' FROM '.$from;

if (count($allFetchedTables) > 1) {
list($columnDescList, $columnsList) = $this->getColumnsList($mainTable, []);
}

Expand Down

0 comments on commit 342c0a3

Please sign in to comment.