I am trying to do a query in Symfony 3 to select the Commentaries of a Wish (Object Wishcom) with the contributionType included (Object ContributionType) thanks to a JOIN.
When running the webpage I get a:
Error: Method Doctrine\ORM\Query\Expr\Func::__toString() must not throw an >exception, caught Symfony\Component\Debug\Exception\ContextErrorException: >Catchable Fatal Error: Object of class DateTime could not be converted to >string
In the forums I could get that the datetime has to be converted with format. The thing is that I am not manipulating directly the date with my query although I know there is one DateTime attribute in my Wishcom object.
Should I select specifically the date and format it ? In that case were should it be done ? Or does the error come from something else ?
It seems the error comes from the where statement and the function ToString from Expr not being able to convert the date. I don't know what I should do.
$queryBuilder->where($queryBuilder->expr()->in('w.wish', $wish));
Here is my call in the controller:
$arraywishcom=$em->getRepository(Wishcom::class)->getWishcomWithContributionType($wish);
And my repository:
<?php
namespace Shaker\JRQBundle\Repository;
use Shaker\JRQBundle\Entity\Wish;
/**
* WishcomRepository
*
* This class was generated by the Doctrine ORM. Add your own custom
* repository methods below.
*/
class WishcomRepository extends \Doctrine\ORM\EntityRepository
{
public function getWishcomWithContributionType(Wish $wish) {
$queryBuilder = $this
->createQueryBuilder('w')
->leftJoin('w.contributiontype', 'contributiontype')
->addSelect('contributiontype')
;
$queryBuilder->where($queryBuilder->expr()->in('w.wish', $wish));
return $queryBuilder
->getQuery()
->getResult()
;
}
}