34 public static function decompose(
Query $query, $fairLimit =
true, $separateRelations =
true)
37 $primaryNames = $entity->getPrimaryArray();
43 $query->
setSelect($entity->getPrimaryArray());
51 return $query->
getEntity()->createCollection();
55 $query = $entity->getDataClass()::query();
57 $query->where(static::getPrimaryFilter($primaryNames, $rows));
61 if ($separateRelations)
66 foreach ($originalSelect as $selectItem)
69 $selQuery = $entity->getDataClass()::query();
70 $selQuery->addSelect($selectItem);
71 $selQuery->getQuery(
true);
74 foreach ($selQuery->getChains() as $chain)
76 if ($chain->hasBackReference())
78 $dividedSelect[] = $selectItem;
83 $commonSelect[] = $selectItem;
86 if (empty($commonSelect))
88 $commonSelect = $query->
getEntity()->getPrimaryArray();
98 if (!empty($dividedSelect) && $collection->count())
104 foreach ($collection as $object)
108 $primaryValues[] = $object->primary;
111 $primaryFilter = static::getPrimaryFilter($primaryNames, $primaryValues);
114 foreach ($dividedSelect as $selectItem)
116 $result = $entity->getDataClass()::query()
117 ->addSelect($selectItem)
118 ->where($primaryFilter)
121 $result->setIdentityMap($im);
122 $result->fetchCollection();
139 if (count($primaryNames) === 1)
143 foreach ($primaryValues as $row)
145 $values[] = $row[$primaryNames[0]];
148 $commonSubFilter->whereIn($primaryNames[0], $values);
152 $commonSubFilter->logic(
'or');
154 foreach ($primaryValues as $row)
158 foreach ($primaryNames as $primaryName)
160 $primarySubFilter->where($primaryName, $row[$primaryName]);
165 return $commonSubFilter;
static getPrimaryFilter($primaryNames, $primaryValues)
setDistinct($distinct=true)
fetchAll(\Bitrix\Main\Text\Converter $converter=null)