Reputation: 157
I'm still having a problem which let me stop on working because I don't get it solved.
I have 2 tables , Task and TaskDone. In Task there is stored the ID of the Task ( ID ) and the User, which the Task is assigned to ( User )
In my TaskDone Table I have the ID of the TaskDone ( ID ) , the ID of the Task which is marked as "done" (Task_ID) and the User which the task marked as done is assigned to ( User_ID )
In my Controller I get All tasks assigned to a specific user by following code ( The request, which task is assigned to a user is done in the TWIG template by a simple IF-Request ) but I also have the chance to get the User ID in my controller ( the ID is in the URL )
$all_tasks = $this->getDoctrine()
->getRepository('SeotoolMainBundle:Task')
->findBy(array('User' => $id));
Now I only want to get all Tasks where task.ID and task.User exists in table TaskDone, so when an entry is done in TaskDone with ID = 1 | User_ID = 20 | Task_ID = 3 and I'm gettin all done tasks from the User with ID 20 I only get the Task with ID 3.
So I'm looking for something like this ( I know this piece of code is wrong )
$done_tasks = $this->getDoctrine()
->getRepository('SeotoolMainBundle:Task')
->findBy(array('User' => $id) IF task.id AND task.user EXISTS in taskDone);
I would be so happy if someone can give me a hint, help or code how to solve this issue.
Thank you in advance,
kind regards
Marvin
Upvotes: 0
Views: 46
Reputation: 2101
You should describe the associations(more info) between your entities, and perform a join(using the QueryBuilder or DQL) between the task
and taskDone
entities.
MySQL docs on JOIN
And a tutorial
Upvotes: 1