mirror of
https://gitee.com/fastadminnet/framework.git
synced 2026-07-08 23:52:49 +08:00
修正多对多关联删除
This commit is contained in:
@@ -256,8 +256,7 @@ class BelongsToMany extends Relation
|
|||||||
$pk = $this->parent->getPk();
|
$pk = $this->parent->getPk();
|
||||||
$pivot[$this->localKey] = $this->parent->$pk;
|
$pivot[$this->localKey] = $this->parent->$pk;
|
||||||
$pivot[$this->foreignKey] = $id;
|
$pivot[$this->foreignKey] = $id;
|
||||||
$query = clone $this->parent->db();
|
return $this->query->table($this->middle)->insert($pivot);
|
||||||
return $query->table($this->middle)->insert($pivot);
|
|
||||||
} else {
|
} else {
|
||||||
throw new Exception('miss relation data');
|
throw new Exception('miss relation data');
|
||||||
}
|
}
|
||||||
@@ -288,8 +287,7 @@ class BelongsToMany extends Relation
|
|||||||
if (isset($id)) {
|
if (isset($id)) {
|
||||||
$pivot[$this->foreignKey] = is_array($id) ? ['in', $id] : $id;
|
$pivot[$this->foreignKey] = is_array($id) ? ['in', $id] : $id;
|
||||||
}
|
}
|
||||||
$query = clone $this->parent->db();
|
$this->query->table($this->middle)->where($pivot)->delete();
|
||||||
$query->table($this->middle)->where($pivot)->delete();
|
|
||||||
|
|
||||||
// 删除关联表数据
|
// 删除关联表数据
|
||||||
if (isset($id) && $relationDel) {
|
if (isset($id) && $relationDel) {
|
||||||
|
|||||||
Reference in New Issue
Block a user