1

I have one to many relationship in two tables. I want to fetch records based on equals values (of specific field) in both the tables. Right now I am doing it like this

$queryProspects = new SugarQuery();
$queryProspects->from(BeanFactory::getBean('Prospects'), array('team_security' => false));
$leads = $queryProspects->join('lead')->joinName();
$queryProspects->select(array("first_name"));
$queryProspects->where()->equals('first_name', 'leads.first_name');
$resultProspects = $queryProspects->execute();

You can see in the equals method I am trying to match first_name of prospects table with the first_name of leads table.

The problem I am facing here is that second argument of equals method is considered as a complete value like 'leads.first_name' rather than the value of first_name field in the leads table. I want to match first_name of prospects table with first_name of leads table. How can I go with it?

  • I think you need to correct table name from lead to leads $queryProspects->join('leads')->joinName(); – Sachin I May 27 '16 at 09:56
  • No, join needs a link, not table name. lead is a link in Prospects > vardefs.php –  May 27 '16 at 11:19

1 Answers1

0
$queryProspects = new SugarQuery();
$queryProspects->from(BeanFactory::getBean('Prospects'), array('team_security' => false));
$leads = $queryProspects->join('lead')->joinName();
$queryProspects->select(array("first_name"));
$queryProspects->where()->equals('first_name', "$leads.first_name");
$resultProspects = $queryProspects->execute();
gooddadmike
  • 2,329
  • 4
  • 26
  • 48