mirror of
https://gitee.com/fastadminnet/framework.git
synced 2026-07-01 20:52:48 +08:00
改进主从读取
This commit is contained in:
@@ -53,6 +53,8 @@ class Query
|
||||
protected static $info = [];
|
||||
// 回调事件
|
||||
private static $event = [];
|
||||
// 读取主库
|
||||
private static $readMaster = [];
|
||||
|
||||
/**
|
||||
* 构造函数
|
||||
@@ -141,16 +143,20 @@ class Query
|
||||
}
|
||||
|
||||
/**
|
||||
* 设置模型从主库读取数据
|
||||
* 设置后续从主库读取数据
|
||||
* @access public
|
||||
* @param bool $master
|
||||
* @return void
|
||||
*/
|
||||
public function setModelReadMaster($master = true)
|
||||
public function readMaster($master = true)
|
||||
{
|
||||
if ($this->model) {
|
||||
$this->model->readMaster($master);
|
||||
if ($master) {
|
||||
$table = isset($this->options['table']) ? $this->options['table'] : $this->getTable();
|
||||
|
||||
static::$readMaster[$table] = true;
|
||||
}
|
||||
|
||||
return $this;
|
||||
}
|
||||
|
||||
/**
|
||||
@@ -2936,6 +2942,10 @@ class Query
|
||||
}
|
||||
}
|
||||
|
||||
if (isset(static::$readMaster[$options['table']])) {
|
||||
$options['master'] = true;
|
||||
}
|
||||
|
||||
foreach (['join', 'union', 'group', 'having', 'limit', 'order', 'force', 'comment'] as $name) {
|
||||
if (!isset($options[$name])) {
|
||||
$options[$name] = '';
|
||||
|
||||
Reference in New Issue
Block a user