If you have an association in place between Task and TaskUser, you don't need
to specify a WITH clause in the LEFT JOIN part of the query. So you can simply
do:
$qb->leftJoin('\Entities\TaskUser', 'tu');
This will probably solve you're problem, because your WITH clause isn't
entirely correct.
If you still get the same error, that would mean that the Task in question
doesn't have an associated TaskUser. Please determine the id of the task and
use that to check the database.
--
Jasper N. Brouwer
(@jaspernbrouwer)
On 21 February 2015 at 21:50:45, Raymond Gonzalez ([email protected]) wrote:
>
>
> I'm not sure if it's that I'm not doing correctly but this is giving me an
> error:
>
> I have 2 Entities: Task and TaskUser. They are connected by a onetoMany.
>
> What I want to do is this:
> foreach($tasks as $task){
> echo $task->getTitle;
> echo $task->getTaskUser()->getFirstName();
> }
>
>
> This is my query in the Task Repository:
> $qb = $this->_em->createQueryBuilder();
>
> $qb
> ->select('t', 'tu')
> ->from('\Entities\Task', 't')
> ->leftJoin('\Entities\TaskUser', 'tu', \Doctrine\ORM\Query\Expr\Join::WITH
> , 't.id = tu.task')
> ->where('tu = :user')
> ->setParameter('user', $user)
> ->orderBy('t.createDate', 'DESC');
>
> return $qb->getQuery()->getResult(\Doctrine\ORM\Query::HYDRATE_OBJECT);
>
>
> When I do this loop:
> foreach($this->view->tasks as $task){
> echo $task->getTitle();
> }
>
>
> I get the the title of the first task, and then an error like this:
> Title of first task
> Fatal error: Call to undefined method Entities\TaskUser::getTitle() in D
> :\sites\db\application\controllers\TasksController.php on line 35
>
>
> Any idea why this is happening? Thanks!
--
You received this message because you are subscribed to the Google Groups
"doctrine-user" group.
To unsubscribe from this group and stop receiving emails from it, send an email
to [email protected].
To post to this group, send email to [email protected].
Visit this group at http://groups.google.com/group/doctrine-user.
For more options, visit https://groups.google.com/d/optout.