Skip to content

Instantly share code, notes, and snippets.

@jbartek
Last active August 29, 2015 14:00
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save jbartek/11049119 to your computer and use it in GitHub Desktop.
Save jbartek/11049119 to your computer and use it in GitHub Desktop.
SugarQuery - Select all contacts that have closed opportunities on accounts of type industry
<?php
$query = new SugarQuery();
$query->from(BeanFactory::getBean('Accounts'));
$contacts = $query->join('contacts')->joinName();
$opp = $query->join('opportunities', array('relatedJoin' => $contacts))->joinName();
$query->select(array("$contacts.full_name", "$opp.name"));
$query->where()->equals('industry','media');
$query->where()->equals("$opp.sales_stage", 'closed');
$results = $query->execute();
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment