• Модуль: main
  • Путь к файлу: ~/bitrix/modules/main/lib/orm/query/query.php
  • Класс: Bitrix\Main\ORM\Query\Query
  • Вызов: Query::buildJoin
protected function buildJoin()
{
	$sql = array();
	$csw = new \CSQLWhere;

	$connection = $this->entity->getConnection();
	$helper = $connection->getSqlHelper();

	foreach ($this->join_map as $join)
	{
		// prepare csw fields
		$csw_fields = $this->getJoinCswFields($join['reference']);
		$csw->setFields($csw_fields);

		if ($join['reference'] instanceof Filter)
		{
			$joinConditionSql = $join['reference']->getSql($this->global_chains);
		}
		else
		{
			$joinConditionSql = trim($csw->getQuery($join['reference']));
		}

		// final sql
		$sql[] = sprintf('%s JOIN %s %s ON %s',
			$join['type'],
			$this->quoteTableSource($join['table']),
			$helper->quote($join['alias']),
			$joinConditionSql
		);
	}

	return "\n".join("\n", $sql);
}