I
I
inavo2020-02-27 19:14:32
1C-Bitrix
inavo, 2020-02-27 19:14:32

How to get id of all elements with binding to elements in properties?

There is an infoblock "one" with a group of elements and an infoblock "two" with a group of elements.
The elements of block 1 have the "binding to elements" property, with the help of which the elements of block 2 are attached to the elements of block 1 as properties.

Everything is fine, as long as we need to get the properties of the elements of block 2 in the element template, this can be done through the parameter

$arResult[PROPERTIES][СИМВОЛЬНЫЙКОДСВОЙСТВА][VALUE]

But if you need to get a property in the section of block 1 where all elements of 1 are displayed, then a problem arises, because PROPERTIES no longer get into arResult, and even through getList by element id they don't exist.

So the question is, how knowing the properties of element 2 (or maybe block 2?) can you get all elements 1 that have a binding to element 2?

Answer the question

In order to leave comments, you need to log in

2 answer(s)
A
Aliy Kunashev, 2020-02-27
@askunash

Thriller pancake)
Getlist treats this, see the parameters.
In general, the connection of tables in both directions without a layer in any database is a bad idea.

S
Sergey, 2020-02-27
@Firsov36

If the old way is like this:

$propertyBrandValue = 'НАЗВАНИЕ';
$iBlockId_1 = 9;

$res = CIBlockElement::GetList(array(),
    array(
        'IBLOCK_ID' => $iBlockId_1,
        '=PROPERTY_C_BRANDS.NAME' => $propertyBrandValue
    ),
    false,
    array('nTopCount' => 10),
    array('ID', 'IBLOCK_ID', 'NAME')
);

while($el = $res->GetNext()) {
    \Bitrix\Main\Diag\Debug::dump($el);
}

=PROPERTY_C_BRANDS.NAME- here you change NAME to a field or property. Description of the method and filtering here: Bitrix documentation
But immediately note that this option makes large requests and has not been advised on busy sites for some time.
On the ORM, you can do it in many ways from medium to complex, but you already need to see where you use this code in order to choose which way to go. The method is more complicated, but simple and fast queries.
Well, I’m not sure that you don’t have any values ​​\u200b\u200bof the first IB there.
In general, the presented code is working and tested, then think for yourself.

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question