修正多对多关联删除

This commit is contained in:
thinkphp
2016-12-07 18:17:45 +08:00
parent c951001f6c
commit 275d04d316

View File

@@ -256,8 +256,7 @@ class BelongsToMany extends Relation
$pk = $this->parent->getPk();
$pivot[$this->localKey] = $this->parent->$pk;
$pivot[$this->foreignKey] = $id;
$query = clone $this->parent->db();
return $query->table($this->middle)->insert($pivot);
return $this->query->table($this->middle)->insert($pivot);
} else {
throw new Exception('miss relation data');
}
@@ -288,8 +287,7 @@ class BelongsToMany extends Relation
if (isset($id)) {
$pivot[$this->foreignKey] = is_array($id) ? ['in', $id] : $id;
}
$query = clone $this->parent->db();
$query->table($this->middle)->where($pivot)->delete();
$this->query->table($this->middle)->where($pivot)->delete();
// 删除关联表数据
if (isset($id) && $relationDel) {