Permalink
Browse files

* Fixed #292: Refactored CActiveRecord so that attribute assignment c…

…an be overridden more easily.
  • Loading branch information...
1 parent 9bbbf9b commit 44f75f31df95506ff4e3fc5a00c9b3dc3fc21a15 qiang.xue committed May 8, 2009
Showing with 6 additions and 15 deletions.
  1. +2 −1 CHANGELOG
  2. +4 −14 framework/db/ar/CActiveRecord.php
View
@@ -81,7 +81,8 @@ Version 1.0.4 April 5, 2009
- New #212: 'Readline' support in yiic console script (olafure)
- New #225: Added trace statements to CActiveRecord and CActiveFinder (Qiang)
- New #230: Enhanced CHtml so that it can be used in situations where controller is absent (Qiang)
-- New #233: allow CFileValidator::types to be set with an array (Qiang)
+- New #233: Allow CFileValidator::types to be set with an array (Qiang)
+- New #292: Refactored CActiveRecord so that attribute assignment can be overridden more easily (Qiang)
- New: Added support to GROUP BY and HAVING in eager loading of AR (Qiang)
- New: Added CClientScript::scriptFiles and CClientScript::cssFiles (Qiang)
- New: Added SQL Server support for Active Record (Christophe)
@@ -426,11 +426,7 @@ public function __get($name)
*/
public function __set($name,$value)
{
- if(isset($this->getMetaData()->columns[$name]))
- $this->_attributes[$name]=$value;
- else if(isset($this->getMetaData()->relations[$name]))
- $this->_related[$name]=$value;
- else
+ if($this->setAttribute($name,$value)===false)
parent::__set($name,$value);
}
@@ -900,7 +896,6 @@ public function hasAttribute($name)
* You may also use $this->AttributeName to obtain the attribute value.
* @param string the attribute name
* @return mixed the attribute value. Null if the attribute is not set or does not exist.
- * @throws CException if the attribute does not exist.
* @see hasAttribute
*/
public function getAttribute($name)
@@ -909,19 +904,14 @@ public function getAttribute($name)
return $this->$name;
else if(isset($this->_attributes[$name]))
return $this->_attributes[$name];
- else if(isset($this->getMetaData()->columns[$name]))
- return null;
- else
- throw new CDbException(Yii::t('yii','{class} does not have attribute "{name}".',
- array('{class}'=>get_class($this), '{name}'=>$name)));
}
/**
* Sets the named attribute value.
* You may also use $this->AttributeName to set the attribute value.
* @param string the attribute name
* @param mixed the attribute value.
- * @throws CException if the attribute does not exist.
+ * @return boolean whether the attribute exists and the assignment is conducted successfully
* @see hasAttribute
*/
public function setAttribute($name,$value)
@@ -931,8 +921,8 @@ public function setAttribute($name,$value)
else if(isset($this->getMetaData()->columns[$name]))
$this->_attributes[$name]=$value;
else
- throw new CDbException(Yii::t('yii','{class} does not have attribute "{name}".',
- array('{class}'=>get_class($this), '{name}'=>$name)));
+ return false;
+ return true;
}
/**

0 comments on commit 44f75f3

Please sign in to comment.