Reputation: 1687
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?
Upvotes: 0
Views: 1318
Reputation: 4761
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 !
Upvotes: 3