Skip to content

Commit

Permalink
set old attributes on init if pk's are set
Browse files Browse the repository at this point in the history
  • Loading branch information
simialbi committed Oct 16, 2017
1 parent 468c55b commit ae79d50
Showing 1 changed file with 11 additions and 0 deletions.
11 changes: 11 additions & 0 deletions ActiveRecord.php
Original file line number Diff line number Diff line change
Expand Up @@ -37,13 +37,24 @@ class ActiveRecord extends BaseActiveRecord {
*/
public function __construct(array $attributes = [], $config = []) {
$this->_isConstructing = true;
$setOld = true;
$keys = $this->primaryKey();
foreach ($keys as $key) {
if (!isset($attributes[$key])) {
$setOld = false;
break;
}
}
foreach ($attributes as $name => $value) {
if (is_int($name)) {
$this->setAttribute($value, null);
} else {
$this->setAttribute($name, $value);
}
}
if ($setOld) {
$this->setOldAttributes($attributes);
}
$this->_isConstructing = false;
parent::__construct($config);
}
Expand Down

0 comments on commit ae79d50

Please sign in to comment.