@@ -34,6 +34,14 @@ class TranslateableBehavior extends Behavior
34
34
* @var string[] the list of attributes to be translated
35
35
*/
36
36
public $ translationAttributes ;
37
+
38
+ /**
39
+ * Temp buffer for entity relations.
40
+ *
41
+ * @var array
42
+ */
43
+ protected $ relationsBuffer = [];
44
+
37
45
38
46
/**
39
47
* @inheritdoc
@@ -83,6 +91,8 @@ public function getTranslation($language = null)
83
91
84
92
foreach ($ translations as $ translation ) {
85
93
if ($ translation ->getAttribute ($ this ->translationLanguageAttribute ) === $ language ) {
94
+ $ this ->relationsBuffer [] = $ translation ;
95
+
86
96
return $ translation ;
87
97
}
88
98
}
@@ -93,6 +103,7 @@ public function getTranslation($language = null)
93
103
$ translation = new $ class ();
94
104
$ translation ->setAttribute ($ this ->translationLanguageAttribute , $ language );
95
105
$ translations [] = $ translation ;
106
+ $ this ->relationsBuffer = $ translations ;
96
107
$ this ->owner ->populateRelation ($ this ->translationRelation , $ translations );
97
108
98
109
return $ translation ;
@@ -135,7 +146,7 @@ public function afterValidate()
135
146
public function afterSave ()
136
147
{
137
148
/* @var ActiveRecord $translation */
138
- foreach ($ this ->owner ->{ $ this -> translationRelation } as $ translation ) {
149
+ foreach ($ this ->relationsBuffer as $ translation ) {
139
150
$ this ->owner ->link ($ this ->translationRelation , $ translation );
140
151
}
141
152
}
0 commit comments