Commit f98c414c by Fourteenmeister

Update QueryBuilder.php

solution used **heukirne** for the names of columns.
parent f46c7060
...@@ -197,7 +197,7 @@ class QueryBuilder extends \yii\db\QueryBuilder ...@@ -197,7 +197,7 @@ class QueryBuilder extends \yii\db\QueryBuilder
$select = $query->select = '*'; $select = $query->select = '*';
} }
if ($select === '*') { if ($select === '*') {
$columns = $this->getAllColumnNames($query->from[0]); $columns = $this->getAllColumnNames($query->modelClass);
if ($columns && is_array($columns)) if ($columns && is_array($columns))
$select = implode(', ', $columns); $select = implode(', ', $columns);
else else
...@@ -209,13 +209,14 @@ class QueryBuilder extends \yii\db\QueryBuilder ...@@ -209,13 +209,14 @@ class QueryBuilder extends \yii\db\QueryBuilder
return $sql; return $sql;
} }
protected function getAllColumnNames($table = null) protected function getAllColumnNames($modelClass = null)
{ {
if (!$table) { if (!$modelClass) {
return null; return null;
} }
$columns = $this->db->createCommand("SELECT COLUMN_NAME FROM INFORMATION_SCHEMA.COLUMNS WHERE TABLE_NAME='{$table}'")->queryColumn(); $model = new $modelClass;
array_walk($columns, create_function('&$str', '$str = "[$str]";')); $schema = $model->getTableSchema();
$columns = array_keys($schema->columns);
return $columns; return $columns;
} }
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment