From a1ad4e97dff2d6a1ebaf8e4b7625dd832def1bc9 Mon Sep 17 00:00:00 2001 From: thinkphp Date: Thu, 2 Nov 2017 17:59:28 +0800 Subject: [PATCH] =?UTF-8?q?=E6=94=B9=E8=BF=9B=E5=A4=9A=E5=AF=B9=E5=A4=9A?= =?UTF-8?q?=E5=85=B3=E8=81=94=E7=9A=84=E4=B8=AD=E9=97=B4=E8=A1=A8=E6=A8=A1?= =?UTF-8?q?=E5=9E=8B=E6=8F=90=E7=A4=BA?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- library/think/model/relation/BelongsToMany.php | 12 +++++++++--- 1 file changed, 9 insertions(+), 3 deletions(-) diff --git a/library/think/model/relation/BelongsToMany.php b/library/think/model/relation/BelongsToMany.php index ef08abb4..7460547b 100644 --- a/library/think/model/relation/BelongsToMany.php +++ b/library/think/model/relation/BelongsToMany.php @@ -68,12 +68,18 @@ class BelongsToMany extends Relation /** * 实例化中间表模型 * @param $data - * @return mixed + * @return Pivot + * @throws Exception */ protected function newPivot($data = []) { - $pivot = $this->pivotName ?: '\\think\\model\\Pivot'; - return new $pivot($this->parent, $data, $this->middle); + $class = $this->pivotName ?: '\\think\\model\\Pivot'; + $pivot = new $class($this->parent, $data, $this->middle); + if ($pivot instanceof Pivot) { + return $pivot; + } else { + throw new Exception('pivot model must extends: \think\model\Pivot'); + } } /**