You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
Copy file name to clipboardExpand all lines: framework/CHANGELOG.md
+1Lines changed: 1 addition & 0 deletions
Display the source diff
Display the rich diff
Original file line number
Diff line number
Diff line change
@@ -4,6 +4,7 @@ Yii Framework 2 Change Log
4
4
2.0.49 under development
5
5
------------------------
6
6
7
+
- Chg #19788: Removed all (often non-functional) attempts of Yii2 to automatically synchronize ActiveRecord relations with corresponding foreign key values. The new guarantee provided by Yii2 is: once set ActiveRecord relations are never automatically or silently changed/unset by the engine (PowerGamer1)
7
8
- Bug #19899: Fixed `GridView` in some cases calling `Model::generateAttributeLabel()` to generate label values that are never used (PowerGamer1)
8
9
- Bug #9899: Fix caching a MSSQL query with BLOB data type (terabytesoftw)
9
10
- Bug #16208: Fix `yii\log\FileTarget` to not export empty messages (terabytesoftw)
Copy file name to clipboardExpand all lines: framework/UPGRADE.md
+23Lines changed: 23 additions & 0 deletions
Display the source diff
Display the rich diff
Original file line number
Diff line number
Diff line change
@@ -62,6 +62,29 @@ Upgrade from Yii 2.0.48
62
62
* The function signature for `yii\console\Controller::select()` and `yii\helpers\BaseConsole::select()` have changed.
63
63
They now have an additional `$default = null` parameter. In case those methods are overwritten you will need to
64
64
update your child classes accordingly.
65
+
* The engine no longer attempts to provide an automatic synchronization between ActiveRecord relations and corresponding foreign keys.
66
+
Such synchronization never worked in many cases, came with ActiveRecord performance and memory costs and in some cases is impossible to achieve (see https://github.com/yiisoft/yii2/issues/19788 for details).
67
+
The new guarantee provided by Yii2 is: once set ActiveRecord relations are never automatically or silently changed/unset by the engine.
68
+
All places in existing code that use already loaded relation after it is expected to change need to manually unset such relation. For example, in the code below:
69
+
```php
70
+
$project = Project::findOne(123);
71
+
$oldManager = $project->manager;
72
+
$project->load(Yii::$app->getRequest()->post()); // $project->manager_id may change here.
73
+
$project->update();
74
+
$newManager = $project->manager;
75
+
// Notify $oldManager and $newManager about the reassignment by email.
76
+
```
77
+
the access to `$project->manager` after update should be preceded by unsetting that relation:
78
+
```PHP
79
+
// ... (same as above).
80
+
$project->update();
81
+
unset($project->manager);
82
+
$newManager = $project->manager;
83
+
// Notify $oldManager and $newManager about the reassignment by email.
84
+
```
85
+
Another notable example is using `ActiveRecord::refresh()`. If the refreshed model had relations loaded before the call to `refresh()`
86
+
and these relations are expected to change, unset them explicitly with `unset()` before using again.
0 commit comments