mirror of
https://codeberg.org/vlw/scaffold.git
synced 2026-02-26 03:21:57 +01:00
fix: pass an optional return value to Database\Model->set() (#28)
This PR addresses a bug that can arise (for example) if an object is passed to a database column that accepts a string. Passing this object (or something else) to the `$return` parameter will return the value of that variable instead of the value of `$value` Reviewed-on: https://codeberg.org/vlw/scaffold/pulls/28
This commit is contained in:
parent
19e15c0b23
commit
fd0c8cbbcd
1 changed files with 3 additions and 2 deletions
|
|
@ -97,9 +97,10 @@
|
|||
*
|
||||
* @param string $key Target column to update
|
||||
* @param mixed $value New value of target column
|
||||
* @param return $return (optional) Return this instead of $value when set
|
||||
* @return mixed The value that was sent to $value
|
||||
*/
|
||||
public function set(string $key, mixed $value): mixed {
|
||||
public function set(string $key, mixed $value, mixed $return = null): mixed {
|
||||
$this->_row[$key] = $value;
|
||||
|
||||
$this->db
|
||||
|
|
@ -107,6 +108,6 @@
|
|||
->where($this->where)
|
||||
->update([$key => $value]);
|
||||
|
||||
return $value;
|
||||
return $return ?? $value;
|
||||
}
|
||||
}
|
||||
|
|
|
|||
Loading…
Add table
Reference in a new issue