From 8de3ffabfee7d6ec279d4a21df0efbdd2c68889f Mon Sep 17 00:00:00 2001 From: Alexander Kochetov Date: Sat, 22 Jun 2013 18:12:51 +0400 Subject: [PATCH 1/2] ActiveRecord::setAttribute() bugfix --- framework/yii/db/ActiveRecord.php | 7 ++++++- 1 file changed, 6 insertions(+), 1 deletion(-) diff --git a/framework/yii/db/ActiveRecord.php b/framework/yii/db/ActiveRecord.php index 37944ff..8f78fac 100644 --- a/framework/yii/db/ActiveRecord.php +++ b/framework/yii/db/ActiveRecord.php @@ -523,11 +523,16 @@ class ActiveRecord extends Model * Sets the named attribute value. * @param string $name the attribute name * @param mixed $value the attribute value. + * @throws InvalidParamException if the named attribute does not exist. * @see hasAttribute */ public function setAttribute($name, $value) { - $this->_attributes[$name] = $value; + if (isset($this->_attributes[$name]) || isset($this->getTableSchema()->columns[$name])) { + $this->_attributes[$name] = $value; + } else { + throw new InvalidParamException(get_class($this) . ' has no attribute named "' . $name . '".'); + } } /** From bb2e19faa52e983d7b39eaef76f8dedeb6c001f9 Mon Sep 17 00:00:00 2001 From: Alexander Kochetov Date: Sat, 22 Jun 2013 21:41:11 +0400 Subject: [PATCH 2/2] ActiveRecord::setOldAttribute() bugfix --- framework/yii/db/ActiveRecord.php | 7 ++++++- 1 file changed, 6 insertions(+), 1 deletion(-) diff --git a/framework/yii/db/ActiveRecord.php b/framework/yii/db/ActiveRecord.php index 8f78fac..7a11288 100644 --- a/framework/yii/db/ActiveRecord.php +++ b/framework/yii/db/ActiveRecord.php @@ -572,11 +572,16 @@ class ActiveRecord extends Model * Sets the old value of the named attribute. * @param string $name the attribute name * @param mixed $value the old attribute value. + * @throws InvalidParamException if the named attribute does not exist. * @see hasAttribute */ public function setOldAttribute($name, $value) { - $this->_oldAttributes[$name] = $value; + if (isset($this->_oldAttributes[$name]) || isset($this->getTableSchema()->columns[$name])) { + $this->_oldAttributes[$name] = $value; + } else { + throw new InvalidParamException(get_class($this) . ' has no attribute named "' . $name . '".'); + } } /**