Relate oneToOne

Collapse
X
 
  • Time
  • Show
Clear All
new posts
  • item
    Active Community Member
    • Mar 2017
    • 1498

    Relate oneToOne

    Hello,
    i have a entity with many oneToOne relation care to patient/meeting/contact.... but something is strange :

    i save care entity with
    PHP Code:
                              'patientId' => $patient->id,
                              'meetingId' => $meeting->id,
                              'contactId' => $contact->id,
                              'institutionId' => $institutionId, 
    
    :
    and too have try with
    PHP Code:
                $entityManager->getRepository('Care')->relate($care, 'patient', $patient);
                $entityManager->getRepository('Care')->relate($care, 'meeting', $meeting);
                $entityManager->getRepository('Care')->relate($care, 'contact', $contact); 
    
    But the result :
    sometime i have :
    patientId is filled sometime .. contactId is filled sometime... i never see all filled !
    all entity is not null, on global->log, all id is there.

    Any help

    Thanks
    If you could give the project a star on GitHub. EspoCrm believe our work truly deserves more recognition. Thanks.​
  • telecastg
    Active Community Member
    • Jun 2018
    • 907

    #2
    Maybe try?

    Code:
    $entity->set("patientId", $patientId);
    // and just to make sure that the update is persisted
    $entityManager->saveEntity($entity);

    Comment

    • item
      Active Community Member
      • Mar 2017
      • 1498

      #3
      Hello Telecastg
      try try .. but really strange.. i have resolved with pdo :


      PHP Code:
      
                  $care = $entityManager->getEntity('Care');
                  $care->set([
                                'name' => $patient->get('name') .' ' .$contact->get('name') ,
                                'date' => $dateCare,
                                'status' => $status,
                                'patientId' => $patient->id,
                                'contactId' => $contact->id,
                                .... other oneToOne ...
                                'amount' =>  $careAmount,
                                'assignedUserId' => $this->getUser()->id,
                                'teamsIds' => ['5d06d441c2e5166d6'],
      
                              ]);
                  $entityManager->saveEntity($care);
                  $careId = $care->id;
                  $sql = "UPDATE care SET  
                      patient_id='{$patientId}',
                      meeting_id='{$meetingId}',
                      contact_id='{$contactId}',
                      institution_id='{$institutionId}',
                      institution_parent_id='{$institutionParentId}',
                      convention_id='{$conventionId}',
                      profession_id='{$professionId}'
                      WHERE id='{$careId}';";
                  $GLOBALS['log']->warning($sql);
                  $sth = $pdo->prepare($sql);
                  $sth->execute(); 
      
      If you could give the project a star on GitHub. EspoCrm believe our work truly deserves more recognition. Thanks.​

      Comment

      Working...