diff --git a/library/think/Model.php b/library/think/Model.php index 9903370b..2179920d 100644 --- a/library/think/Model.php +++ b/library/think/Model.php @@ -859,10 +859,10 @@ abstract class Model implements \JsonSerializable, \ArrayAccess /** * 初始化数据库对象 - * @access public + * @access protected * @return \think\db\Query */ - public static function db() + protected static function db() { $model = get_called_class(); if (!isset(self::$links[$model])) { @@ -894,7 +894,7 @@ abstract class Model implements \JsonSerializable, \ArrayAccess call_user_func_array([$this, $method], $args); return $this; } else { - throw new Exception(__CLASS__ . ':' . $method . ' method not exist'); + return call_user_func_array([self::db(), $method], $args); } } diff --git a/library/think/model/Merge.php b/library/think/model/Merge.php index 6f35b297..05918fac 100644 --- a/library/think/model/Merge.php +++ b/library/think/model/Merge.php @@ -66,7 +66,7 @@ class Merge extends Model foreach (static::$relationModel as $key => $model) { $name = is_int($key) ? $model : $key; - $table = is_int($key) ? self::db()->getTable($name) : $model; + $table = is_int($key) ? $query->getTable($name) : $model; $query->join($table . ' ' . $name, $name . '.' . $class->fk . '=' . $master . '.' . $class->getPk()); $fields = self::getModelField($name, $table, $class->mapFields); $query->field($fields);