mirror of
https://gitee.com/fastadminnet/framework.git
synced 2026-07-05 14:52:47 +08:00
多对多关联支持指定中间表数据名称
after/before验证支持指定字段验证
This commit is contained in:
@@ -29,6 +29,8 @@ class BelongsToMany extends Relation
|
||||
protected $pivotName;
|
||||
// 中间表模型对象
|
||||
protected $pivot;
|
||||
// 中间表数据名称
|
||||
protected $pivotDataName = 'pivot';
|
||||
|
||||
/**
|
||||
* 构造函数
|
||||
@@ -70,6 +72,18 @@ class BelongsToMany extends Relation
|
||||
return $this;
|
||||
}
|
||||
|
||||
/**
|
||||
* 设置中间表数据名称
|
||||
* @access public
|
||||
* @param string $name
|
||||
* @return $this
|
||||
*/
|
||||
public function pivotDataName($name)
|
||||
{
|
||||
$this->pivotDataName = $name;
|
||||
return $this;
|
||||
}
|
||||
|
||||
/**
|
||||
* 获取中间表更新条件
|
||||
* @param $data
|
||||
@@ -118,7 +132,7 @@ class BelongsToMany extends Relation
|
||||
}
|
||||
}
|
||||
}
|
||||
$model->setRelation('pivot', $this->newPivot($pivot, true));
|
||||
$model->setRelation($this->pivotDataName, $this->newPivot($pivot, true));
|
||||
}
|
||||
}
|
||||
|
||||
@@ -384,7 +398,7 @@ class BelongsToMany extends Relation
|
||||
}
|
||||
}
|
||||
}
|
||||
$set->setRelation('pivot', $this->newPivot($pivot, true));
|
||||
$set->setRelation($this->pivotDataName, $this->newPivot($pivot, true));
|
||||
$data[$pivot[$this->localKey]][] = $set;
|
||||
}
|
||||
return $data;
|
||||
|
||||
Reference in New Issue
Block a user