Skip to content

Commit

Permalink
refresh relations with BC break
Browse files Browse the repository at this point in the history
+ implementation with BC break
  • Loading branch information
chriscpty committed Dec 6, 2024
1 parent 4ed589f commit 2c6f34d
Show file tree
Hide file tree
Showing 3 changed files with 9 additions and 4 deletions.
5 changes: 3 additions & 2 deletions framework/db/ActiveRecord.php
Original file line number Diff line number Diff line change
Expand Up @@ -281,7 +281,7 @@ protected static function filterValidColumnNames($db, array $aliases)
/**
* {@inheritdoc}
*/
public function refresh()
public function refresh(array $with = [])
{
$query = static::find();
$tableName = key($query->getTablesUsedInFrom());
Expand All @@ -290,7 +290,8 @@ public function refresh()
foreach ($this->getPrimaryKey(true) as $key => $value) {
$pk[$tableName . '.' . $key] = $value;
}
$query->where($pk);
$query->where($pk)
->with(...$with);

/* @var $record BaseActiveRecord */
$record = $query->noCache()->one();
Expand Down
4 changes: 2 additions & 2 deletions framework/db/BaseActiveRecord.php
Original file line number Diff line number Diff line change
Expand Up @@ -1082,8 +1082,8 @@ protected function refreshInternal($record)
$this->_attributes[$name] = isset($record->_attributes[$name]) ? $record->_attributes[$name] : null;
}
$this->_oldAttributes = $record->_oldAttributes;
$this->_related = [];
$this->_relationsDependencies = [];
$this->_related = $record->_related;
$this->_relationsDependencies = $record->_relationsDependencies;
$this->afterRefresh();

return true;
Expand Down
4 changes: 4 additions & 0 deletions tests/framework/ar/ActiveRecordTestTrait.php
Original file line number Diff line number Diff line change
Expand Up @@ -288,6 +288,10 @@ public function testRefresh()
$customer->name = 'to be refreshed';
$this->assertTrue($customer->refresh());
$this->assertEquals('user1', $customer->name);
$this->assertFalse($customer->isRelationPopulated('profile'));

$this->assertTrue($customer->refresh(['profile']));
$this->assertTrue($customer->isRelationPopulated('profile'));
}

public function testEquals()
Expand Down

0 comments on commit 2c6f34d

Please sign in to comment.