Bitrix-D7 23.9
 
Загрузка...
Поиск...
Не найдено
query.php
1<?php
9namespace Bitrix\Iblock\ORM;
10
13use Bitrix\Main\ORM\Query\Query as BaseQuery;
14
22class Query extends BaseQuery
23{
24 protected function buildJoin()
25 {
26 // collapse v2.0 single value joins into one
27 if ($this->entity instanceof ElementV2Entity)
28 {
29 // table alias for all the records (cut b_ prefix)
30 $propSTable = $this->entity->getSingleValueTableName();
31 $commonAlias = mb_substr($propSTable, 2);
32
33 // found first join and changed alias. all other joins to be removed
34 $changed = false;
35
36 // table aliases to be changed in chains
37 $replacedAliases = [];
38
39 // 1. collapse joins
40 foreach ($this->join_map as $k => $join)
41 {
42 // check join
43 if ($join['table'] === $propSTable && $join['type'] === Join::TYPE_INNER)
44 {
46 $conditions = $join['reference']->getConditions();
47
48 // check on condition
49 if (count($conditions) === 1 && $conditions[0]->getColumn() === 'ID' && $conditions[0]->getOperator() === '=')
50 {
51 // collect table aliases to rewrite in chains
52 $replacedAliases[$join['alias']] = true;
53
54 if (!$changed)
55 {
56 // make the only one change
57 $this->join_map[$k]['alias'] = $commonAlias;
58
59 $changed = true;
60 }
61 else
62 {
63 // remove from registry
64 unset($this->join_map[$k]);
65 }
66
67 }
68 }
69 }
70
71 // 2. rewrite aliases
72 foreach ($this->global_chains as $chain)
73 {
74 if (!empty($replacedAliases[$chain->getLastElement()->getParameter('talias')]))
75 {
76 $chain->getLastElement()->setParameter('talias', $commonAlias);
77 }
78 }
79 }
80
81 return parent::buildJoin();
82 }
83}