Using Doctrine 2 and Symfony 2.7 I want to use an automated count for a column in my db.
Example:
So when I update a report, I want to add the user (which is the parent of the report by a OneToMany relation) to the leaderboards with the column completed set to 1 (setCompleted). When the user was already on the leaderboards, I want to find him and add 1 to the completed tasks value.
if (!$lb) { $new = New Leaderboard(); $new->setUsers($user) ->setCompleted('1'); $em->persist($new); } else { $update = $em->getRepository('AppBundle:Leaderboard')->findBy(array('user' => $user)); $update->setCompleted('2'); }
So basically I want to automate the $update->setCompleted('2');
so that it takes the current value and adds one to that and then flush that to the database.
I hope this makes any sense? No sure how to explain it or search for it online...