mirror of
https://gitee.com/fastadminnet/framework.git
synced 2026-07-01 20:52:48 +08:00
修正Query类的builder方法
This commit is contained in:
@@ -853,10 +853,11 @@ abstract class Model implements \JsonSerializable, \ArrayAccess
|
||||
|
||||
if (!isset(self::$links[$model])) {
|
||||
self::$links[$model] = Db::connect(static::$connection);
|
||||
self::$links[$model]->setTable(static::$tableName);
|
||||
$name = basename(str_replace('\\', '/', $model));
|
||||
self::$links[$model]->name($name);
|
||||
}
|
||||
self::$links[$model]->setTable(static::$tableName);
|
||||
$name = basename(str_replace('\\', '/', $model));
|
||||
self::$links[$model]->name($name);
|
||||
|
||||
// 设置当前模型 确保查询返回模型对象
|
||||
self::$links[$model]->model($model);
|
||||
// 返回当前数据库对象
|
||||
|
||||
@@ -38,10 +38,20 @@ abstract class Builder
|
||||
* @access public
|
||||
* @param object $db 数据库对象实例
|
||||
*/
|
||||
public function __construct($connection, $query)
|
||||
public function __construct($connection)
|
||||
{
|
||||
$this->connection = $connection;
|
||||
$this->query = $query;
|
||||
}
|
||||
|
||||
/**
|
||||
* 设置当前的Query对象实例
|
||||
* @access protected
|
||||
* @param \think\db\Query $query 当前查询对象实例
|
||||
* @return void
|
||||
*/
|
||||
public function setQuery($query)
|
||||
{
|
||||
$this->query = $query;
|
||||
}
|
||||
|
||||
/**
|
||||
@@ -299,13 +309,13 @@ abstract class Builder
|
||||
if ($value instanceof \Closure) {
|
||||
$whereStr .= $key . ' ' . $exp . ' ' . $this->parseClosure($value);
|
||||
} else {
|
||||
$value = is_array($value) ? $value : explode(',', $value) ;
|
||||
$value = is_array($value) ? $value : explode(',', $value);
|
||||
$zone = implode(',', $this->parseValue($value));
|
||||
$whereStr .= $key . ' ' . $exp . ' (' . $zone . ')';
|
||||
}
|
||||
} elseif (in_array($exp, ['NOT BETWEEN', 'BETWEEN'])) {
|
||||
// BETWEEN 查询
|
||||
$data = is_array($value) ? $value : explode(',', $value) ;
|
||||
$data = is_array($value) ? $value : explode(',', $value);
|
||||
$whereStr .= $key . ' ' . $exp . ' ' . $this->parseValue($data[0]) . ' AND ' . $this->parseValue($data[1]);
|
||||
} elseif (in_array($exp, ['NOT EXISTS', 'EXISTS'])) {
|
||||
// EXISTS 查询
|
||||
|
||||
@@ -77,8 +77,10 @@ class Query
|
||||
$driver = $this->driver;
|
||||
if (!isset($builder[$driver])) {
|
||||
$class = '\\think\\db\\builder\\' . ucfirst($driver);
|
||||
$builder[$driver] = new $class($this->connection, $this);
|
||||
$builder[$driver] = new $class($this->connection);
|
||||
}
|
||||
// 设置当前查询对象
|
||||
$builder[$driver]->setQuery($this);
|
||||
return $builder[$driver];
|
||||
}
|
||||
|
||||
|
||||
Reference in New Issue
Block a user