getMediaRelationRepository(); $mediaRelations = $repository ->findAllByTarget(new FindAllByTargetQuery($mediaId, MediaRelation::MEDIA_TYPE)) ->getIterator(); /** @var MediaRelation $media */ foreach ($mediaRelations as $mediaRelation) { $repository->remove($mediaRelation); } } private function getMediaRelationRepository(): MediaRelationRepositoryInterface { return $this->getServiceLocator()->get(MediaRelationRepositoryInterface::SERVICE_ID); } }