mirror of
https://gitee.com/fastadminnet/framework.git
synced 2026-07-01 12:42:48 +08:00
增加Pivot对象parent属性
This commit is contained in:
@@ -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;
|
||||
}
|
||||
|
||||
|
||||
@@ -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);
|
||||
}
|
||||
|
||||
/**
|
||||
|
||||
Reference in New Issue
Block a user