Answer the question
In order to leave comments, you need to log in
How to make a complex getList request in 1C-Bitrix?
Hello! There are highloadblock elements, the infoblock element id is stored in the UF_ELEMENT_ID field. The next question is how to make a complex getList request for a selection from a highloadblock so that I can immediately get some fields (name, properties) of the linked infoblock element? The selection is currently being made
use Bitrix\Highloadblock as HL;
Bitrix\Main\Loader::includeModule('highloadblock');
$hlblock = HL\HighloadBlockTable::getById($hlBlockId)->fetch(); // $hlBlockId = 11
$entity = HL\HighloadBlockTable::compileEntity($hlblock);
$dataClass = $entity->getDataClass();
$result = $dataClass::getList([
"select" => array('*'), //выбираем все поля
]);
$arCache = [];
while($arElement = $result->fetch())
{
// тут у меня каждый элемент обрабатывается, делаю запрос и кэширую, чтобы обращаться 1 раз
if (!array_key_exists($arElement["UF_ELEMENT_ID"], $arCache))
{
$res = CIBlockElement::GetByID($arElement["UF_ELEMENT_ID"]);
$arCache[$arElement["UF_ELEMENT_ID"]] = $res->Fetch();
}
// тут собираю все в один массив
}
Answer the question
In order to leave comments, you need to log in
Something like this, if you need infoblock fields:
use Bitrix\Main\Application;
use Bitrix\Highloadblock\HighloadBlockTable;
use Bitrix\Main\Loader;
Loader::includeModule('highloadblock');
Loader::includeModule('iblock');
$hlBlockId = 2;
$hlblock = HighloadBlockTable::getById($hlBlockId)->fetch();
/** @var \Bitrix\Main\Entity\Base $entity */
$entity = HighloadBlockTable::compileEntity($hlblock);
/** @var \Bitrix\Main\Entity\DataManager $dataClass */
$dataClass = $entity->getDataClass();
Application::getConnection()->startTracker();
$result = $dataClass::getList([
'select' => array(
'UF_ELEMENT_ID',
'NAME' => 'ELEMENT.NAME',
'CODE' => 'ELEMENT.CODE',
'DETAIL_PICTURE' => 'ELEMENT.DETAIL_PICTURE',
),
'runtime' => array(
'ELEMENT' => array(
'data_type' => '\Bitrix\Iblock\ElementTable',
'reference' => array(
'=this.UF_ELEMENT_ID' => 'ref.ID'
),
'join_type' => 'inner'
),
),
'limit' => 10,
]);
// Можно смотреть сформированный запрос
echo '<pre>', $result->getTrackerQuery()->getSql(), '</pre>';
while ($row = $result->fetch()) {
echo '<pre>';print_r($row);echo '</pre>';
}
Didn't find what you were looking for?
Ask your questionAsk a Question
731 491 924 answers to any question