eee
This commit is contained in:
+13
-11
@@ -483,9 +483,7 @@ abstract class Model extends Component implements ModelInterface, ArrayAccess, \
|
|||||||
return FALSE;
|
return FALSE;
|
||||||
}
|
}
|
||||||
if (!$this->isNewExample) {
|
if (!$this->isNewExample) {
|
||||||
[$changes, $condition] = $this->diff();
|
return $this->updateInternal(...$this->arrayIntersect($this->_attributes));
|
||||||
|
|
||||||
return $this->updateInternal($condition, $condition, $changes);
|
|
||||||
} else {
|
} else {
|
||||||
return $this->insert();
|
return $this->insert();
|
||||||
}
|
}
|
||||||
@@ -493,18 +491,22 @@ abstract class Model extends Component implements ModelInterface, ArrayAccess, \
|
|||||||
|
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* @return array<array, array>
|
* @return array<array, array, array>
|
||||||
* @throws
|
* @throws
|
||||||
*/
|
*/
|
||||||
private function diff(): array
|
protected function arrayIntersect(array $params): array
|
||||||
{
|
{
|
||||||
$changes = \array_diff_assoc($this->_attributes, $this->_oldAttributes);
|
$condition = [];
|
||||||
if ($this->hasPrimary()) {
|
$oldPrams = [];
|
||||||
$condition = [$this->primary => $this->_oldAttributes[$this->primary]];
|
foreach ($this->_oldAttributes as $key => $attribute) {
|
||||||
} else {
|
if (!array_key_exists($key, $params) || $params[$key] == $attribute) {
|
||||||
$condition = \array_intersect_assoc($this->_oldAttributes, $this->_attributes);
|
$condition[$key] = $attribute;
|
||||||
|
unset($params[$key]);
|
||||||
|
} else {
|
||||||
|
$oldPrams[$key] = $this->_oldAttributes[$attribute];
|
||||||
|
}
|
||||||
}
|
}
|
||||||
return [$changes, $condition];
|
return [$oldPrams, $condition, $params];
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
|
|||||||
@@ -195,17 +195,7 @@ class Model extends Base\Model
|
|||||||
if (!$this->validator($this->rules()) || !$this->beforeSave($this)) {
|
if (!$this->validator($this->rules()) || !$this->beforeSave($this)) {
|
||||||
return FALSE;
|
return FALSE;
|
||||||
}
|
}
|
||||||
|
return $this->updateInternal(...$this->arrayIntersect($params));
|
||||||
$condition = [];
|
|
||||||
$oldPrams = [];
|
|
||||||
foreach ($this->_oldAttributes as $key => $attribute) {
|
|
||||||
if (!array_key_exists($key, $params) || $params[$key] == $attribute) {
|
|
||||||
$condition[$key] = $attribute;
|
|
||||||
} else {
|
|
||||||
$oldPrams[$key] = $this->_oldAttributes[$attribute];
|
|
||||||
}
|
|
||||||
}
|
|
||||||
return $this->updateInternal($oldPrams, $condition, $params);
|
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
|
|||||||
Reference in New Issue
Block a user