From 0952e9231f6c64c979015440b68ad5226d02b775 Mon Sep 17 00:00:00 2001 From: yunwuxin <448901948@qq.com> Date: Thu, 2 Mar 2017 16:06:37 +0800 Subject: [PATCH] =?UTF-8?q?=E5=A2=9E=E5=8A=A0Pivot=E5=AF=B9=E8=B1=A1parent?= =?UTF-8?q?=E5=B1=9E=E6=80=A7?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- library/think/model/Pivot.php | 12 +++++++++--- library/think/model/relation/BelongsToMany.php | 2 +- 2 files changed, 10 insertions(+), 4 deletions(-) diff --git a/library/think/model/Pivot.php b/library/think/model/Pivot.php index 9fd45719..423921d7 100644 --- a/library/think/model/Pivot.php +++ b/library/think/model/Pivot.php @@ -16,13 +16,17 @@ use think\Model; class Pivot extends Model { + /** @var Model */ + public $parent; + /** * 构造函数 * @access public - * @param array|object $data 数据 - * @param string $table 中间数据表名 + * @param Model $parent + * @param array|object $data 数据 + * @param string $table 中间数据表名 */ - public function __construct($data = [], $table = '') + public function __construct(Model $parent, $data = [], $table = '') { if (is_object($data)) { $this->data = get_object_vars($data); @@ -30,6 +34,8 @@ class Pivot extends Model $this->data = $data; } + $this->parent = $parent; + $this->table = $table; } diff --git a/library/think/model/relation/BelongsToMany.php b/library/think/model/relation/BelongsToMany.php index 89eacfa1..acf945f6 100644 --- a/library/think/model/relation/BelongsToMany.php +++ b/library/think/model/relation/BelongsToMany.php @@ -64,7 +64,7 @@ class BelongsToMany extends Relation protected function newPivot($data) { $pivot = $this->pivot ?: '\\think\\model\\Pivot'; - return new $pivot($data, $this->middle); + return new $pivot($this->parent, $data, $this->middle); } /**