yii2 save model with relations

I have 3 models User, UserTranslation, Translation, which are related User->UserTranslation->Translation. Also I have getters and setters:

public function getUserTranslation(){

    return $this->hasMany(UserTranslation::className(), ['user_id' => 'id']);


public function setUserTranslation($value){

    $this->populateRelation('userTranslation', $value);


I am trying to save User object with his relations data at once.

public function addToDb($rus_words,$eng_words){

    $user = User::findOne(Yii::$app->user->getId());

    $i = 0;

    foreach($rus_words as $key => $value){    

        $translation = new Translation();

        $translation->word = $key;

        $translation->translate = $eng_words[$i];

        $user_translation = new UserTranslation();

        $user_translation->translation = $translation;

        $user_translation->count = $value;

        $user->userTranslation[] = $user_translation;





On this line:

$user->userTranslation[] = $user_translation //where $user->userTranslation is an array of Translation objects

i have an error Indirect modification of overloaded element of app\models\User has no effect.

Even if I try to add an auxilary array and then assign it to $user->userTranslation, $user->save() doesn’t save anything.

Help me please with your advices or tell maybe where are some methods to insert a whole collention to DB?