S
S
sashavol2021-08-04 18:33:08
1C-Bitrix
sashavol, 2021-08-04 18:33:08

How to link data in many-to-many Bitrix with different types of Iblock, highload entities?

Please tell me how difficult it is to make the following request:
1) Entity No. 1
CCrmQoute - these are offers in Bitrix24

2) Entity No. 2
Highloadblock - a linking table, contains the ID of the offer and the ID of the infoblock element

3) Entity No. 3
IblockElement - a regular element of the infoblock

Is there a solution which will allow me to make a request without cycles when I get all the elements of the infoblock attached to it for the required "offer"?

Those. I have an offer ID for example 100, I write a beautiful ORM selection and by 120 ID I get a list of elements bound to it with their data and properties :))

Answer the question

In order to leave comments, you need to log in

1 answer(s)
P
PetrPo, 2021-08-04
@sashavol

Something like this, if I understood correctly

\Bitrix\Main\Loader::includeModule('highloadblock');

use Bitrix\Highloadblock as HL; 
use Bitrix\Main\Entity;

// ID HL-блока
$hlbl = 2;
$hlblock = HL\HighloadBlockTable::getById($hlbl)->fetch(); 

$entity = HL\HighloadBlockTable::compileEntity($hlblock); 
$entity_data_class = $entity->getDataClass(); 

// CRM_QUOTE_ID
$crmQuoteId = 100;
// XML_ID UF поля с CRM_QUOTE_ID в HL-блоке
$crmQuoteFieldId = 'UF_CRM_QUOTE_ID';

$result = $entity_data_class::getList([
  'select' => ['ELEMENT_' => 'IBLOCK_ELEMENT'],
  'order' => [],
  'filter' => [$crmQuoteFieldId => $crmQuoteId],
  'runtime' => [
    'IBLOCK_ELEMENT' => [
      'data_type' => \Bitrix\Iblock\ElementTable::class,
      'reference' => ['this.'.$crmQuoteFieldId => 'ref.ID'],
      'join' => 'RIGHT'
    ]
  ]
])->fetchAll();

print_r($result);

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question