改进多对多关联的中间表模型提示

This commit is contained in:
thinkphp
2017-11-02 17:59:28 +08:00
parent 83fbae0d2b
commit a1ad4e97df

View File

@@ -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');
}
}
/**