Skip to content

Commit

Permalink
Revert "fix: filterExecuteAttributes 地址引用导致aop后变量指针错误的问题" (#106)
Browse files Browse the repository at this point in the history
This reverts commit 5aaefc6207242a7d48c2abe273fed1d778b40e67.
  • Loading branch information
zds-s authored Jul 1, 2024
1 parent 336ef5e commit f25f860
Showing 1 changed file with 7 additions and 6 deletions.
13 changes: 7 additions & 6 deletions src/Traits/MapperTrait.php
Original file line number Diff line number Diff line change
Expand Up @@ -231,7 +231,7 @@ public function filterQueryAttributes(array $fields, bool $removePk = false): ar
/**
* 过滤新增或写入不存在的字段.
*/
public function filterExecuteAttributes(array $data, bool $removePk = false): array
public function filterExecuteAttributes(array &$data, bool $removePk = false): void
{
$model = new $this->model();
$attrs = $model->getFillable();
Expand All @@ -244,16 +244,15 @@ public function filterExecuteAttributes(array $data, bool $removePk = false): ar
unset($data[$model->getKeyName()]);
}
$model = null;

return $data;
}

/**
* 新增数据.
*/
public function save(array $data): mixed
{
$model = $this->model::create($this->filterExecuteAttributes($data, $this->getModel()->incrementing));
$this->filterExecuteAttributes($data, $this->getModel()->incrementing);
$model = $this->model::create($data);
return $model->{$model->getKeyName()};
}

Expand Down Expand Up @@ -316,15 +315,17 @@ public function delete(array $ids): bool
*/
public function update(mixed $id, array $data): bool
{
return $this->model::find($id)->update($this->filterExecuteAttributes($data, true)) > 0;
$this->filterExecuteAttributes($data, true);
return $this->model::find($id)->update($data) > 0;
}

/**
* 按条件更新数据.
*/
public function updateByCondition(array $condition, array $data): bool
{
return $this->model::query()->where($condition)->update($this->filterExecuteAttributes($data, true)) > 0;
$this->filterExecuteAttributes($data, true);
return $this->model::query()->where($condition)->update($data) > 0;
}

/**
Expand Down

0 comments on commit f25f860

Please sign in to comment.