M
M
Maxim2015-10-16 00:40:41
symfony
Maxim, 2015-10-16 00:40:41

Why is the object not being deleted?

I'm trying to delete a record from the database, but I've run into a problem.
They make it clear to me that there is no "remove" method

Undefined method 'remove'. The method name must start with either findBy or findOneBy!

And actually the question is how to remove it?
class VoteHandler implements VoteHandlerInterface{
    private $om;
    private $entityClass;
    private $repository;
    private $formFactory;

    public function __construct(ObjectManager $om, $entityClass, FormFactoryInterface $formFactory){
        $this->om = $om;
        $this->entityClass = $entityClass;
        $this->repository = $this->om->getRepository($this->entityClass);
        $this->formFactory = $formFactory;
    }
public function delete($id){
        $vote = $this->repository->findOneById($id);
        $this->repository->remove($vote);
        $this->repository->flush();
        return true;
    }
}

Or is it all about the ObjectManager?
And by the way, I will be grateful if you explain what is the difference with EntityManager

Answer the question

In order to leave comments, you need to log in

1 answer(s)
D
Denis, 2015-10-16
@maxpointn2point

$this-> repository ->remove($vote);
$this-> repository ->flush();
Well, implement these methods in the repository, if you don't want to delete the manager...
upd: ObjectManager is an interface, and EntityManager implements this interface.

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question