diff --git a/ActiveRecord.php b/ActiveRecord.php index b12af65..2b07a8e 100644 --- a/ActiveRecord.php +++ b/ActiveRecord.php @@ -24,6 +24,11 @@ class ActiveRecord extends BaseActiveRecord { */ protected $_attributes = []; + /** + * @var boolean if in construction process (modifies behavior of hasAttribute method) + */ + private $_isConstructing = false; + /** * Constructors. * @@ -31,13 +36,15 @@ class ActiveRecord extends BaseActiveRecord { * @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); } @@ -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