protected function sortManyManyRelation(
        ManyManyList $relation,
        array $idList,
        array $rawList,
        DataObjectInterface $record,
        $sortColumn
    ) {
        $relation->getForeignID();
        $ownerIdField = $relation->getForeignKey();
        $fileIdField = $relation->getLocalKey();
        $joinTable = '"' . $relation->getJoinTable() . '"';
        $sort = 0;
        foreach ($rawList as $id) {
            if (in_array($id, $idList)) {
                // Use SQLUpdate to update the data in the join-table.
                // This is safe to do, since new records have already been written to the DB in the
                // parent::saveInto call.
                SQLUpdate::create($joinTable)
                    ->setWhere([
                        "\"$ownerIdField\" = ?" => $record->ID,
                        "\"$fileIdField\" = ?" => $id
                    ])
                    ->assign($sortColumn, $sort++)
                    ->execute();
            }
        }
    }