Commit fa767cea by Carsten Brandt

renamed attributes to attributeNames in model

fixes #3034
parent 3fdcf11f
......@@ -443,7 +443,7 @@ abstract class ActiveRecord extends BaseActiveRecord
*
* @param boolean $runValidation whether to perform validation before saving the record.
* If the validation fails, the record will not be inserted into the database.
* @param array $attributes list of attributes that need to be saved. Defaults to null,
* @param array $attributeNames list of attributes that need to be saved. Defaults to null,
* meaning all attributes that are loaded from DB will be saved.
* @return integer|boolean the number of rows affected, or false if validation fails
* or [[beforeSave()]] stops the updating process.
......@@ -451,16 +451,16 @@ abstract class ActiveRecord extends BaseActiveRecord
* being updated is outdated.
* @throws \Exception in case update failed.
*/
public function update($runValidation = true, $attributes = null)
public function update($runValidation = true, $attributeNames = null)
{
if ($runValidation && !$this->validate($attributes)) {
if ($runValidation && !$this->validate($attributeNames)) {
return false;
}
$db = static::getDb();
if ($this->isTransactional(self::OP_UPDATE) && $db->getTransaction() === null) {
$transaction = $db->beginTransaction();
try {
$result = $this->updateInternal($attributes);
$result = $this->updateInternal($attributeNames);
if ($result === false) {
$transaction->rollBack();
} else {
......@@ -471,7 +471,7 @@ abstract class ActiveRecord extends BaseActiveRecord
throw $e;
}
} else {
$result = $this->updateInternal($attributes);
$result = $this->updateInternal($attributeNames);
}
return $result;
......
......@@ -302,14 +302,14 @@ class Model extends Component implements IteratorAggregate, ArrayAccess, Arrayab
* Errors found during the validation can be retrieved via [[getErrors()]],
* [[getFirstErrors()]] and [[getFirstError()]].
*
* @param array $attributes list of attributes that should be validated.
* @param array $attributeNames list of attribute names that should be validated.
* If this parameter is empty, it means any attribute listed in the applicable
* validation rules should be validated.
* @param boolean $clearErrors whether to call [[clearErrors()]] before performing validation
* @return boolean whether the validation is successful without any error.
* @throws InvalidParamException if the current scenario is unknown.
*/
public function validate($attributes = null, $clearErrors = true)
public function validate($attributeNames = null, $clearErrors = true)
{
$scenarios = $this->scenarios();
$scenario = $this->getScenario();
......@@ -320,12 +320,12 @@ class Model extends Component implements IteratorAggregate, ArrayAccess, Arrayab
if ($clearErrors) {
$this->clearErrors();
}
if ($attributes === null) {
$attributes = $this->activeAttributes();
if ($attributeNames === null) {
$attributeNames = $this->activeAttributes();
}
if ($this->beforeValidate()) {
foreach ($this->getActiveValidators() as $validator) {
$validator->validateAttributes($this, $attributes);
$validator->validateAttributes($this, $attributeNames);
}
$this->afterValidate();
......@@ -791,18 +791,18 @@ class Model extends Component implements IteratorAggregate, ArrayAccess, Arrayab
* This method will validate every model. The models being validated may
* be of the same or different types.
* @param array $models the models to be validated
* @param array $attributes list of attributes that should be validated.
* @param array $attributeNames list of attribute names that should be validated.
* If this parameter is empty, it means any attribute listed in the applicable
* validation rules should be validated.
* @return boolean whether all models are valid. False will be returned if one
* or multiple models have validation error.
*/
public static function validateMultiple($models, $attributes = null)
public static function validateMultiple($models, $attributeNames = null)
{
$valid = true;
/** @var Model $model */
foreach ($models as $model) {
$valid = $model->validate($attributes) && $valid;
$valid = $model->validate($attributeNames) && $valid;
}
return $valid;
......@@ -906,7 +906,6 @@ class Model extends Component implements IteratorAggregate, ArrayAccess, Arrayab
public function getIterator()
{
$attributes = $this->getAttributes();
return new ArrayIterator($attributes);
}
......
......@@ -480,7 +480,7 @@ class ActiveRecord extends BaseActiveRecord
*
* @param boolean $runValidation whether to perform validation before saving the record.
* If the validation fails, the record will not be inserted into the database.
* @param array $attributes list of attributes that need to be saved. Defaults to null,
* @param array $attributeNames list of attributes that need to be saved. Defaults to null,
* meaning all attributes that are loaded from DB will be saved.
* @return integer|boolean the number of rows affected, or false if validation fails
* or [[beforeSave()]] stops the updating process.
......@@ -488,9 +488,9 @@ class ActiveRecord extends BaseActiveRecord
* being updated is outdated.
* @throws \Exception in case update failed.
*/
public function update($runValidation = true, $attributes = null)
public function update($runValidation = true, $attributeNames = null)
{
if ($runValidation && !$this->validate($attributes)) {
if ($runValidation && !$this->validate($attributeNames)) {
Yii::info('Model not updated due to validation error.', __METHOD__);
return false;
}
......@@ -498,7 +498,7 @@ class ActiveRecord extends BaseActiveRecord
if ($this->isTransactional(self::OP_UPDATE)) {
$transaction = $db->beginTransaction();
try {
$result = $this->updateInternal($attributes);
$result = $this->updateInternal($attributeNames);
if ($result === false) {
$transaction->rollBack();
} else {
......@@ -509,7 +509,7 @@ class ActiveRecord extends BaseActiveRecord
throw $e;
}
} else {
$result = $this->updateInternal($attributes);
$result = $this->updateInternal($attributeNames);
}
return $result;
......
......@@ -272,11 +272,11 @@ interface ActiveRecordInterface
* @param boolean $runValidation whether to perform validation before saving the record.
* If the validation fails, the record will not be saved to database. `false` will be returned
* in this case.
* @param array $attributes list of attributes that need to be saved. Defaults to null,
* @param array $attributeNames list of attributes that need to be saved. Defaults to null,
* meaning all attributes that are loaded from DB will be saved.
* @return boolean whether the saving succeeds
*/
public function save($runValidation = true, $attributes = null);
public function save($runValidation = true, $attributeNames = null);
/**
* Inserts the record into the database using the attribute values of this record.
......@@ -312,14 +312,14 @@ interface ActiveRecordInterface
*
* @param boolean $runValidation whether to perform validation before saving the record.
* If the validation fails, the record will not be inserted into the database.
* @param array $attributes list of attributes that need to be saved. Defaults to null,
* @param array $attributeNames list of attributes that need to be saved. Defaults to null,
* meaning all attributes that are loaded from DB will be saved.
* @return integer|boolean the number of rows affected, or false if validation fails
* or updating process is stopped for other reasons.
* Note that it is possible that the number of rows affected is 0, even though the
* update execution is successful.
*/
public function update($runValidation = true, $attributes = null);
public function update($runValidation = true, $attributeNames = null);
/**
* Deletes the record from the database.
......
......@@ -565,16 +565,16 @@ abstract class BaseActiveRecord extends Model implements ActiveRecordInterface
*
* @param boolean $runValidation whether to perform validation before saving the record.
* If the validation fails, the record will not be saved to database.
* @param array $attributes list of attributes that need to be saved. Defaults to null,
* @param array $attributeNames list of attribute names that need to be saved. Defaults to null,
* meaning all attributes that are loaded from DB will be saved.
* @return boolean whether the saving succeeds
*/
public function save($runValidation = true, $attributes = null)
public function save($runValidation = true, $attributeNames = null)
{
if ($this->getIsNewRecord()) {
return $this->insert($runValidation, $attributes);
return $this->insert($runValidation, $attributeNames);
} else {
return $this->update($runValidation, $attributes) !== false;
return $this->update($runValidation, $attributeNames) !== false;
}
}
......@@ -620,7 +620,7 @@ abstract class BaseActiveRecord extends Model implements ActiveRecordInterface
*
* @param boolean $runValidation whether to perform validation before saving the record.
* If the validation fails, the record will not be inserted into the database.
* @param array $attributes list of attributes that need to be saved. Defaults to null,
* @param array $attributeNames list of attribute names that need to be saved. Defaults to null,
* meaning all attributes that are loaded from DB will be saved.
* @return integer|boolean the number of rows affected, or false if validation fails
* or [[beforeSave()]] stops the updating process.
......@@ -628,12 +628,12 @@ abstract class BaseActiveRecord extends Model implements ActiveRecordInterface
* being updated is outdated.
* @throws \Exception in case update failed.
*/
public function update($runValidation = true, $attributes = null)
public function update($runValidation = true, $attributeNames = null)
{
if ($runValidation && !$this->validate($attributes)) {
if ($runValidation && !$this->validate($attributeNames)) {
return false;
}
return $this->updateInternal($attributes);
return $this->updateInternal($attributeNames);
}
/**
......
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