mirror of
https://gitee.com/fastadminnet/framework.git
synced 2026-07-09 16:12:49 +08:00
改进模型readmaster方法
This commit is contained in:
@@ -180,14 +180,15 @@ abstract class Model implements \JsonSerializable, \ArrayAccess
|
|||||||
/**
|
/**
|
||||||
* 是否从主库读取数据(主从分布有效)
|
* 是否从主库读取数据(主从分布有效)
|
||||||
* @access public
|
* @access public
|
||||||
* @param bool $master 是否从主库读取
|
* @param bool $all 是否所有模型生效
|
||||||
* @return void
|
* @return $this
|
||||||
*/
|
*/
|
||||||
public function readMaster($master = true)
|
public function readMaster($all = false)
|
||||||
{
|
{
|
||||||
if ($master) {
|
$model = $all ? '*' : $this->class;
|
||||||
static::$readMaster[$this->class] = true;
|
|
||||||
}
|
static::$readMaster[$model] = true;
|
||||||
|
return $this;
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
@@ -213,7 +214,7 @@ abstract class Model implements \JsonSerializable, \ArrayAccess
|
|||||||
$queryClass = $this->query ?: $con->getConfig('query');
|
$queryClass = $this->query ?: $con->getConfig('query');
|
||||||
$query = new $queryClass($con, $this);
|
$query = new $queryClass($con, $this);
|
||||||
|
|
||||||
if (isset(static::$readMaster[$this->class])) {
|
if (isset(static::$readMaster['*']) || isset(static::$readMaster[$this->class])) {
|
||||||
$query->master(true);
|
$query->master(true);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
Reference in New Issue
Block a user