0

We have such repository

class CronInfoCharacterInfoRepository extends EntityRepository
{
    /**
     * @param string|integer $characterID
     * @return void
     */
    public function add($characterID)
    {
        if (!$this->find($characterID)) {

            $oEntry = new CronInfoCharacterInfo();
            $oEntry->setCharacterID($characterID);

            $this->getEntityManager()->persist($oEntry);
            $this->getEntityManager()->flush();
        }
    }
}

But I want insert new entry by DQL. How can I do this through $this->createQueryBuilder()... ? And is it normal to use 'entity manager' inside repository?

1 Answer 1

3

You cant insert using DQL the very documentation says about that

INSERT statements are not allowed in DQL, because entities and their relations have to be introduced into the persistence context through EntityManager#persist() to ensure consistency of your object model.

http://docs.doctrine-project.org/en/latest/reference/dql-doctrine-query-language.html

And it is perfectly ok to use enitity manager inside Repo. What you are doing now is correct !

Sign up to request clarification or add additional context in comments.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.