mirror of
https://gitee.com/fastadminnet/framework.git
synced 2026-07-07 23:22:48 +08:00
改进Relation的detach方法
This commit is contained in:
@@ -640,14 +640,16 @@ class Relation
|
|||||||
$id = $data->$relationFk;
|
$id = $data->$relationFk;
|
||||||
}
|
}
|
||||||
// 删除中间表数据
|
// 删除中间表数据
|
||||||
$pk = $this->parent->getPk();
|
$pk = $this->parent->getPk();
|
||||||
$pivot[$this->localKey] = $this->parent->$pk;
|
$pivot[$this->localKey] = $this->parent->$pk;
|
||||||
$pivot[$this->foreignKey] = is_array($id) ? ['in', $id] : $id;
|
if (isset($id)) {
|
||||||
$query = clone $this->parent->db();
|
$pivot[$this->foreignKey] = is_array($id) ? ['in', $id] : $id;
|
||||||
|
}
|
||||||
|
$query = clone $this->parent->db();
|
||||||
$query->table($this->middle)->where($pivot)->delete();
|
$query->table($this->middle)->where($pivot)->delete();
|
||||||
|
|
||||||
// 删除关联表数据
|
// 删除关联表数据
|
||||||
if ($relationDel) {
|
if (isset($id) && $relationDel) {
|
||||||
$model = $this->model;
|
$model = $this->model;
|
||||||
$model::destroy($id);
|
$model::destroy($id);
|
||||||
}
|
}
|
||||||
|
|||||||
Reference in New Issue
Block a user