Fixes #15522: Fixed yii\db\ActiveRecord::refresh() method does not use an alias in the condition

This commit is contained in:
Гордиенко Владислав Юрьевич
2018-02-01 14:13:19 +05:00
committed by Alexander Makarov
parent b3130be7ba
commit 1a1fb49426
4 changed files with 57 additions and 3 deletions

View File

@ -3,7 +3,7 @@ Yii Framework 2 Change Log
2.0.14 under development
------------------------
- Bug #15522: Fixed `yii\db\ActiveRecord::refresh()` method does not use an alias in the condition (vladis84)
- Enh #15476: Added `\yii\widgets\ActiveForm::$validationStateOn` to be able to specify where to add class for invalid fields (samdark)
- Enh #13996: Added `yii\web\View::registerJsVar()` method that allows registering JavaScript variables (Eseperio, samdark)
- Enh #9771: Assign hidden input with its own set of HTML options via `$hiddenOptions` in activeFileInput `$options` (HanafiAhmat)

View File

@ -194,13 +194,17 @@ class ActiveRecord extends BaseActiveRecord
*/
public function refresh()
{
$query = static::find();
$tableName = key($query->getTablesUsedInFrom());
$pk = [];
// disambiguate column names in case ActiveQuery adds a JOIN
foreach ($this->getPrimaryKey(true) as $key => $value) {
$pk[static::tableName() . '.' . $key] = $value;
$pk[$tableName . '.' . $key] = $value;
}
$query->where($pk);
/* @var $record BaseActiveRecord */
$record = static::findOne($pk);
$record = $query->one();
return $this->refreshInternal($record);
}