【发布时间】:2015-05-24 01:03:18
【问题描述】:
我有两个模型:
用户和 资源
而关系表是resource_user。
resource_user 中的字段是:
标识 |资源 ID |用户 ID |另一个_id
我在用户中有这种关系:
public function resources() {
return $this->belongsToMany('Resource')->withPivot(array(
'value',
'another_id',
));
}
现在我想更新我的数据透视表:
(在模型用户中有这个代码示例)
$this->resources()->whereAnotherId(1)->updateExistingPivot($resource_id, array(
'value' => $value,
'updated_at' => new DateTime,
));
问题在于 another_id。
如果我的关系表中有两个条目 (resource_user) 但与 不同 another_id 的。在这个例子中,laravel 将更新两个条目。但这不是我想要的。 在此示例中,应仅更新一个条目(another_id = 1 的条目)。 这是一个错误,或者我如何更新我的数据透视表(sync() 函数不适用于我的表设置)..
【问题讨论】:
标签: php laravel model eloquent relationship