K
K
Kirill Gorelov2019-07-30 11:57:39
1C-Bitrix
Kirill Gorelov, 2019-07-30 11:57:39

Bitrix, I give up CIBlockElement::SubQuery?

I need to get the name of an element from another infoblock by its id (element) (the id of the element I have is "binding to the element")
Now it's done like this:

$arSelect = Array("ID", "NAME", "PROPERTY_c_serv", "PROPERTY_P_CAT_VALUE");
$arFilter = Array("IBLOCK_ID" => "10");
$res = CIBlockElement::GetList(Array(), $arFilter, false, array("nPageSize" => 25), $arSelect);
while($arFields = $res->fetch()){
    //тут я делаю дополнительный запрос
    $arSelect_cat = Array("ID", "NAME");
    $arFilter_cat = Array("IBLOCK_ID"=>"11", "ACTIVE"=>"Y","ID"=>$arFields["PROPERTY_P_CAT_VALUE"]);
    $res_cat = CIBlockElement::GetList(Array(), $arFilter_cat, false, false, $arSelect_cat);
    while($ob_cat = $res_cat->GetNextElement()){
        $arFields_cat = $ob_cat->GetFields();
        $arFields["category"] = $arFields_cat["NAME"];
    }
}

Well, respectively, this is not at any gate.
Therefore, I want to make a request using CIBlockElement::SubQuery ( Documentation )
I have already rewritten it several times, nothing changes, absolutely.
I rewrote it like this:
$arSelect = Array("ID", "NAME", "PROPERTY_c_serv", "PROPERTY_P_CAT_VALUE");
$arFilter = Array("IBLOCK_ID" => "10", "ID" => CIBlockElement::SubQuery("NAME", array("IBLOCK_ID"=>"11", "ACTIVE"=>"Y","ID"=>$arFields["PROPERTY_P_CAT_VALUE"])));
$res = CIBlockElement::GetList(Array(), $arFilter, false, array("nPageSize" => 25), $arSelect);
while($arFields = $res->fetch()){
    //код
}

And as a result, nothing changes. No error is displayed, nothing happens, as the request was the way it worked.
What am I doing wrong? Who has already done such under requests, tell me, I will be very grateful. Or at least poke where I did wrong (

Answer the question

In order to leave comments, you need to log in

3 answer(s)
R
Roman Gritsuk, 2019-07-31
@Kirill-Gorelov

If I understand correctly, you have two IBs on your site. Let's say IB1 and IB2.
In IB1 there is a property of type "Binding to infoblock element". When querying elements from IB1, you want to select the fields of elements from IB2 that are linked to the elements of IB1.
This does not require additional requests.
Opening the documentation on CIblockElement::GetList
Here is what is written there about the selection of such data
PROPERTY_{PROPERTY_CODE}.PROPERTY_{PROPERTY_CODE2} - by property value of the element specified as a binding. PROPERTY_CODE - symbolic code of the element binding type property. PROPERTY_CODE2 - property code of related elements.
Thus, in order to select the name of the attached element in your case, it will be enough to pass PROPERTY_P_CAT.NAME in $arSelect

A
Anton, 2019-07-30
@anton99zel

$arSelect = Array("ID", "NAME", "PROPERTY_c_serv", "PROPERTY_P_CAT_VALUE");
$arFilter = Array("IBLOCK_ID" => "10");
$res = CIBlockElement::GetList(Array(), $arFilter, false, array("nPageSize" => 25), $arSelect);
while($arFields = $res->fetch()){
$ID = $arFields["PROPERTY_P_CAT_VALUE"];
$rest = CIBlockElement::GetByID($ID);
  if($ar_rest = $rest->GetNext())
  		echo $ar_rest['NAME']; // Название элемента 
}

And write character codes in the system in capital letters

S
Sergey Valitov, 2019-10-16
@serejatoje

Roman Gritsuk
I have such a situation, a selection by number in the proposal.

$arSubQuery = array(
                '>CATALOG_QUANTITY' => 0,
            );
            $arrFilter = array_merge(
                array(
                    'ID' => CIBlockElement::SubQuery('PROPERTY_CML2_LINK', $arSubQuery)
                )
            );

And if the product has no offers, and its quantity > 0, then it is not displayed. How can I add a condition to my request to filter both products by quantity in PROPERTY_CML2_LINK and by their own quantity? Add LOGIC OR?

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question