How to update a field in doctrine to set it null

doctrine, doctrine-orm, php, query-builder, symfony

Solution

When you set the value with PHP null script , it's not understood for doctrine because when transforming to the native sql ,he will not replace null with null value as string , so to resolve , pass the null value as string like

$qb->set('q.deletedAt','NULL');

Problem

I want to set null to a field in doctrine and here is the sentence ``` $em = $this->getDoctrine()->getManager(); $qb = $em->createQueryBuilder(); $query = $qb->update('Model\Example', 'u')->set('u.deletedAt', ':deletedAt') ->where("u.id IN (:ids)")->setParameter('deletedAt', null) ->setParameter('ids', $ids) ->getQuery(); $query->execute(); ``` i think that this code should do the job, but im getting this exception An exception occurred while executing 'UPDATE example SET deleted_at = ? WHERE (id IN (?)) AND (example.deleted_at IS NULL)' with params [null, "5,6"]: SQLSTATE[22P02]: Invalid text representation: 7 ERROR: la sintaxis de entrada no es válida para integer: «5,6» first of all why doctrine is adding that AND (example.deleted_at IS NULL) am i doing something wrong ?

Original source