Skip to content

Commit 8dfe8eb

Browse files
committed
改进Query类
1 parent d58ec1b commit 8dfe8eb

File tree

3 files changed

+18
-37
lines changed

3 files changed

+18
-37
lines changed

src/think/App.php

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -21,7 +21,7 @@
2121
*/
2222
class App extends Container
2323
{
24-
const VERSION = '5.2.0beta1';
24+
const VERSION = '5.2.0beta2';
2525

2626
/**
2727
* 应用名称

src/think/Model.php

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -771,7 +771,6 @@ public static function create(array $data, array $field = [], bool $replace = fa
771771
* 更新数据
772772
* @access public
773773
* @param array $data 数据数组
774-
* @param array $where 更新条件
775774
* @param array $field 允许字段
776775
* @return static
777776
*/

src/think/db/Query.php

Lines changed: 17 additions & 35 deletions
Original file line numberDiff line numberDiff line change
@@ -833,32 +833,23 @@ protected function getJoinTable($join, &$alias = null)
833833
if (is_array($join)) {
834834
$table = $join;
835835
$alias = array_shift($join);
836-
} else {
837-
$join = trim($join);
836+
return $table;
837+
}
838838

839-
if (false !== strpos($join, '(')) {
840-
// 使用子查询
841-
$table = $join;
842-
} else {
843-
$prefix = $this->prefix;
844-
if (strpos($join, ' ')) {
845-
// 使用别名
846-
list($table, $alias) = explode(' ', $join);
847-
} else {
848-
$table = $join;
849-
if (false === strpos($join, '.') && 0 !== strpos($join, '__')) {
850-
$alias = $join;
851-
}
852-
}
839+
$join = trim($join);
853840

854-
if ($prefix && false === strpos($table, '.') && 0 !== strpos($table, $prefix) && 0 !== strpos($table, '__')) {
855-
$table = $this->getTable($table);
856-
}
857-
}
841+
if (false !== strpos($join, '(')) {
842+
// 使用子查询
843+
$table = $join;
844+
} elseif (strpos($join, ' ')) {
845+
// 使用别名
846+
list($table, $alias) = explode(' ', $join);
847+
} else {
848+
$table = $join;
849+
}
858850

859-
if (isset($alias) && $table != $alias) {
860-
$table = [$table => $alias];
861-
}
851+
if (isset($alias) && $table != $alias) {
852+
$table = [$table => $alias];
862853
}
863854

864855
return $table;
@@ -1673,7 +1664,7 @@ public function table($table)
16731664
if (is_string($table)) {
16741665
if (strpos($table, ')')) {
16751666
// 子查询
1676-
} elseif (strpos($table, ',')) {
1667+
} else {
16771668
$tables = explode(',', $table);
16781669
$table = [];
16791670

@@ -1686,11 +1677,6 @@ public function table($table)
16861677
$table[] = $item;
16871678
}
16881679
}
1689-
} elseif (strpos($table, ' ')) {
1690-
list($table, $alias) = explode(' ', $table);
1691-
1692-
$table = [$table => $alias];
1693-
$this->alias($table);
16941680
}
16951681
} else {
16961682
$tables = $table;
@@ -1791,7 +1777,7 @@ public function orderRaw(string $field, array $bind = [])
17911777
}
17921778

17931779
/**
1794-
* 指定Field排序 order('id',[1,2,3],'desc')
1780+
* 指定Field排序 orderField('id',[1,2,3],'desc')
17951781
* @access public
17961782
* @param string $field 排序字段
17971783
* @param array $values 排序值
@@ -1907,11 +1893,7 @@ public function alias($alias)
19071893
if (is_array($alias)) {
19081894
$this->options['alias'] = $alias;
19091895
} else {
1910-
if (isset($this->options['table'])) {
1911-
$table = is_array($this->options['table']) ? key($this->options['table']) : $this->options['table'];
1912-
} else {
1913-
$table = $this->getTable();
1914-
}
1896+
$table = $this->getTable();
19151897

19161898
$this->options['alias'][$table] = $alias;
19171899
}

0 commit comments

Comments
 (0)