Commit e9d7a220 by Qiang Xue

Merge pull request #576 from creocoder/ar-set-attribute

ActiveRecord::setAttribute() bugfix
parents 6c5dfc04 bb2e19fa
...@@ -523,11 +523,16 @@ class ActiveRecord extends Model ...@@ -523,11 +523,16 @@ class ActiveRecord extends Model
* Sets the named attribute value. * Sets the named attribute value.
* @param string $name the attribute name * @param string $name the attribute name
* @param mixed $value the attribute value. * @param mixed $value the attribute value.
* @throws InvalidParamException if the named attribute does not exist.
* @see hasAttribute * @see hasAttribute
*/ */
public function setAttribute($name, $value) public function setAttribute($name, $value)
{ {
if (isset($this->_attributes[$name]) || isset($this->getTableSchema()->columns[$name])) {
$this->_attributes[$name] = $value; $this->_attributes[$name] = $value;
} else {
throw new InvalidParamException(get_class($this) . ' has no attribute named "' . $name . '".');
}
} }
/** /**
...@@ -567,11 +572,16 @@ class ActiveRecord extends Model ...@@ -567,11 +572,16 @@ class ActiveRecord extends Model
* Sets the old value of the named attribute. * Sets the old value of the named attribute.
* @param string $name the attribute name * @param string $name the attribute name
* @param mixed $value the old attribute value. * @param mixed $value the old attribute value.
* @throws InvalidParamException if the named attribute does not exist.
* @see hasAttribute * @see hasAttribute
*/ */
public function setOldAttribute($name, $value) public function setOldAttribute($name, $value)
{ {
if (isset($this->_oldAttributes[$name]) || isset($this->getTableSchema()->columns[$name])) {
$this->_oldAttributes[$name] = $value; $this->_oldAttributes[$name] = $value;
} else {
throw new InvalidParamException(get_class($this) . ' has no attribute named "' . $name . '".');
}
} }
/** /**
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment