Commit 6c6dd011 by Qiang Xue

Fixes #1052: unset related data when ActiveRecord::refresh() is called.

parent 9ca98d62
......@@ -1125,26 +1125,20 @@ class ActiveRecord extends Model
/**
* Repopulates this active record with the latest data.
* @param array $attributes
* @return boolean whether the row still exists in the database. If true, the latest data
* will be populated to this active record.
* will be populated to this active record. Otherwise, this record will remain unchanged.
*/
public function refresh($attributes = null)
public function refresh()
{
$record = $this->find($this->getPrimaryKey(true));
if ($record === null) {
return false;
}
if ($attributes === null) {
foreach ($this->attributes() as $name) {
$this->_attributes[$name] = $record->_attributes[$name];
}
$this->_oldAttributes = $this->_attributes;
} else {
foreach ($attributes as $name) {
$this->_oldAttributes[$name] = $this->_attributes[$name] = $record->_attributes[$name];
}
foreach ($this->attributes() as $name) {
$this->_attributes[$name] = $record->_attributes[$name];
}
$this->_oldAttributes = $this->_attributes;
$this->_related = null;
return true;
}
......
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