Skip to content

Commit

Permalink
改进Query类
Browse files Browse the repository at this point in the history
  • Loading branch information
liu21st committed Nov 23, 2018
1 parent d58ec1b commit 8dfe8eb
Show file tree
Hide file tree
Showing 3 changed files with 18 additions and 37 deletions.
2 changes: 1 addition & 1 deletion src/think/App.php
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,7 @@
*/
class App extends Container
{
const VERSION = '5.2.0beta1';
const VERSION = '5.2.0beta2';

/**
* 应用名称
Expand Down
1 change: 0 additions & 1 deletion src/think/Model.php
Original file line number Diff line number Diff line change
Expand Up @@ -771,7 +771,6 @@ public static function create(array $data, array $field = [], bool $replace = fa
* 更新数据
* @access public
* @param array $data 数据数组
* @param array $where 更新条件
* @param array $field 允许字段
* @return static
*/
Expand Down
52 changes: 17 additions & 35 deletions src/think/db/Query.php
Original file line number Diff line number Diff line change
Expand Up @@ -833,32 +833,23 @@ protected function getJoinTable($join, &$alias = null)
if (is_array($join)) {
$table = $join;
$alias = array_shift($join);
} else {
$join = trim($join);
return $table;
}

if (false !== strpos($join, '(')) {
// 使用子查询
$table = $join;
} else {
$prefix = $this->prefix;
if (strpos($join, ' ')) {
// 使用别名
list($table, $alias) = explode(' ', $join);
} else {
$table = $join;
if (false === strpos($join, '.') && 0 !== strpos($join, '__')) {
$alias = $join;
}
}
$join = trim($join);

if ($prefix && false === strpos($table, '.') && 0 !== strpos($table, $prefix) && 0 !== strpos($table, '__')) {
$table = $this->getTable($table);
}
}
if (false !== strpos($join, '(')) {
// 使用子查询
$table = $join;
} elseif (strpos($join, ' ')) {
// 使用别名
list($table, $alias) = explode(' ', $join);
} else {
$table = $join;
}

if (isset($alias) && $table != $alias) {
$table = [$table => $alias];
}
if (isset($alias) && $table != $alias) {
$table = [$table => $alias];
}

return $table;
Expand Down Expand Up @@ -1673,7 +1664,7 @@ public function table($table)
if (is_string($table)) {
if (strpos($table, ')')) {
// 子查询
} elseif (strpos($table, ',')) {
} else {
$tables = explode(',', $table);
$table = [];

Expand All @@ -1686,11 +1677,6 @@ public function table($table)
$table[] = $item;
}
}
} elseif (strpos($table, ' ')) {
list($table, $alias) = explode(' ', $table);

$table = [$table => $alias];
$this->alias($table);
}
} else {
$tables = $table;
Expand Down Expand Up @@ -1791,7 +1777,7 @@ public function orderRaw(string $field, array $bind = [])
}

/**
* 指定Field排序 order('id',[1,2,3],'desc')
* 指定Field排序 orderField('id',[1,2,3],'desc')
* @access public
* @param string $field 排序字段
* @param array $values 排序值
Expand Down Expand Up @@ -1907,11 +1893,7 @@ public function alias($alias)
if (is_array($alias)) {
$this->options['alias'] = $alias;
} else {
if (isset($this->options['table'])) {
$table = is_array($this->options['table']) ? key($this->options['table']) : $this->options['table'];
} else {
$table = $this->getTable();
}
$table = $this->getTable();

$this->options['alias'][$table] = $alias;
}
Expand Down

0 comments on commit 8dfe8eb

Please sign in to comment.