Skip to content

Commit

Permalink
changed behavior of setting attributes to be sure, under laying base
Browse files Browse the repository at this point in the history
active record's private attributes property get filled
  • Loading branch information
simialbi committed Oct 16, 2017
1 parent bcc69b2 commit 7105f81
Showing 1 changed file with 16 additions and 2 deletions.
18 changes: 16 additions & 2 deletions ActiveRecord.php
Original file line number Diff line number Diff line change
Expand Up @@ -24,20 +24,27 @@ class ActiveRecord extends BaseActiveRecord {
*/
protected $_attributes = [];

/**
* @var boolean if in construction process (modifies behavior of hasAttribute method)
*/
private $_isConstructing = false;

/**
* Constructors.
*
* @param array $attributes the dynamic attributes (name-value pairs, or names) being defined
* @param array $config the configuration array to be applied to this object.
*/
public function __construct(array $attributes = [], $config = []) {
$this->_isConstructing = true;
foreach ($attributes as $name => $value) {
if (is_int($name)) {
$this->_attributes[$value] = null;
$this->setAttribute($value, null);
} else {
$this->_attributes[$name] = $value;
$this->setAttribute($value, null);
}
}
$this->_isConstructing = false;
parent::__construct($config);
}

Expand All @@ -48,6 +55,13 @@ public static function instantiate($row) {
return new static($row);
}

/**
* @inheritdoc
*/
public function hasAttribute($name) {
return $this->_isConstructing ? true : parent::hasAttribute($name);
}

/**
* @return null|Connection
* @throws InvalidConfigException
Expand Down

0 comments on commit 7105f81

Please sign in to comment.