Commit c73cfe14 by Carsten Brandt

Fixed inconsistencies with setting old attributes and pks

issue #2892
parent 6f552e0f
......@@ -242,6 +242,7 @@ abstract class ActiveRecord extends BaseActiveRecord
}
$newId = static::getCollection()->insert($values);
$this->setAttribute('_id', $newId);
$values['_id'] = $newId;
$this->afterSave(true);
$this->setOldAttributes($values);
......
......@@ -147,6 +147,7 @@ abstract class ActiveRecord extends \yii\mongodb\ActiveRecord
$newId = $collection->insert($values);
}
$this->setAttribute('_id', $newId);
$values['_id'] = $newId;
$this->afterSave(true);
$this->setOldAttributes($values);
......
......@@ -445,7 +445,7 @@ class ActiveRecord extends BaseActiveRecord
if ($this->getAttribute($name) === null) {
$id = $db->getLastInsertID($table->sequenceName);
$this->setAttribute($name, $id);
$this->setOldAttribute($name, $id);
$values[$name] = $id;
break;
}
}
......
......@@ -24,7 +24,8 @@ use yii\base\InvalidCallException;
* @property array $dirtyAttributes The changed attribute values (name-value pairs). This property is
* read-only.
* @property boolean $isNewRecord Whether the record is new and should be inserted when calling [[save()]].
* @property array $oldAttributes The old attribute values (name-value pairs).
* @property array $oldAttributes The old attribute values (name-value pairs). Note that the type of this
* property differs in getter and setter. See [[getOldAttributes()]] and [[setOldAttributes()]] for details.
* @property mixed $oldPrimaryKey The old primary key value. An array (column name => column value) is
* returned if the primary key is composite. A string is returned otherwise (null will be returned if the key
* value is null). This property is read-only.
......@@ -477,6 +478,7 @@ abstract class BaseActiveRecord extends Model implements ActiveRecordInterface
* Sets the old attribute values.
* All existing old attribute values will be discarded.
* @param array|null $values old attribute values to be set.
* If set to `null` this record is considered to be [[isNewRecord|new]].
*/
public function setOldAttributes($values)
{
......
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