protected function setRelation(array $value, $viaTableName, $localTableId, $foreignTableId, $activeRecordId)
    {
        Yii::$app->db->createCommand()->delete($viaTableName, [$localTableId => $activeRecordId])->execute();
        $batch = [];
        foreach ($value as $k => $v) {
            // $this->id: the value of the current database model, example when relation ins on user model id would be user id
            // $v['id'] extra field values foreached from the join table, so id will represent the joined table pk.

            // issue #696 array logic
            if (is_array($v)) { // its an array and is based on the logic of the angular checkbox releation ['id' => 123] // new: 'value' => 123 since beta6
                if (isset($v['value'])) {
                    $batch[] = [$activeRecordId, $v['value']];
                }
            } else { // its not an array so it could have been assigned from the frontend
                $batch[] = [$activeRecordId, $v];
            }
        }
        if (!empty($batch)) {
            Yii::$app->db->createCommand()->batchInsert($viaTableName, [$localTableId, $foreignTableId], $batch)->execute();
        }
        return true;
    }