public function getEntityRelationshipWhereSql($column, $relationship = null, $relationship_guid = null, $inverse_relationship = false)
{
if ($relationship == null && $relationship_guid == null) {
return '';
}
$wheres = array();
$joins = array();
$group_by = '';
if ($inverse_relationship) {
$joins[] = "JOIN {$this->db->prefix}entity_relationships r on r.guid_one = {$column}";
} else {
$joins[] = "JOIN {$this->db->prefix}entity_relationships r on r.guid_two = {$column}";
}
if ($relationship) {
$wheres[] = "r.relationship = '" . $this->db->sanitizeString($relationship) . "'";
}
if ($relationship_guid) {
if ($inverse_relationship) {
$wheres[] = "r.guid_two = '{$relationship_guid}'";
} else {
$wheres[] = "r.guid_one = '{$relationship_guid}'";
}
} else {
// See #5775. Queries that do not include a relationship_guid must be grouped by entity table alias,
// otherwise the result set is not unique
$group_by = $column;
}
if ($where_str = implode(' AND ', $wheres)) {
return array('wheres' => array("({$where_str})"), 'joins' => $joins, 'group_by' => $group_by);
}
return '';
}