Announcement

Collapse
No announcement yet.

Finding all leads with specific phone number (entities by related entity field value)

Collapse
X
 
  • Filter
  • Time
  • Show
Clear All
new posts

  • Finding all leads with specific phone number (entities by related entity field value)

    I want to get each Lead that has a specific phone number associated (primary or secondary). I am confused on the correct way to get them.
    My code below returns only one Lead, but I manually confirmed there is more than one with the same phone number.

    Code:
    $num = '1234567890';
    $r = $entityManager->getRepository('Lead');
    $f = $r->join('phone_numbers')->where(['phoneNumbers.numeric' => $num])->find();
    echo($f->count()." Leads with number $num found...".PHP_EOL);
    
    foreach($f as $L){
      echo($L->id).PHP_EOL);
    }
    Please advise! Thanks

  • #2
    I think it is because of join
    check it https://github.com/espocrm/espocrm/b...dress.php#L200

    Comment


    • #3
      I still do not understand how join should be used to find all the Leads that have the same (numeric) phone number... in the end I used a two step search using findrelated and entitylist from phone id, but I would like to better understande cross-entity searching. I would've liked to make a single sql query in the backend.

      Comment

      Working...
      X