protected function reduceRelations(&$resource, array $relationNames)
    {
        $keep = [];
        $keepName = [];
        $totalReduced = 0;
        foreach ($resource->relations as $relation) {

            if (in_array($relation->getName(), $relationNames) || in_array($relation->getName(), $keepName)) {
                $totalReduced++;
                continue;
            }

            $keep[] = $relation;
            $keepName[] = $relation->getName();
        }

        $resource->relations = $keep;

        return $totalReduced;
    }