I have this piece of code:
$entity = $em->getRepository('AppBundle:Representative')->find($soqlObj1['records'][0]['Id']); if ($entity === null) { $entity = new Representative(); $em->persist($entity); } // we set the values from veeva $entity->setVeevaRepId($soqlObj1['records'][0]['Id']); $entity->setEmail($soqlObj1['records'][0]['Email']); ... $em->flush();
And this is part of the Representative entity:
class Representative { protected $veeva_rep_id; protected $display_name; protected $avatar_url = 'https://pdone.s3.amazonaws.com/avatar/default_avatar.png'; protected $rep_type = "VEEVA"; protected $username; protected $first; protected $last; protected $title; protected $bio; protected $phone; protected $email; protected $inactive = false; protected $lastLoginAt; protected $lastSyncAt; protected $territory; protected $repTokenId; ... }
There are several other columns that are required at the DB level (nullable = false at the entity level), my question is: if the object does not exist in the DB, it will be created or updated based on the code I wrote, or do I need to move each required field to conditional? What is the right way to achieve this? I am trying to do INSERT|UPDATE based on only one query result
source share