D
D
d6core2021-10-16 14:21:20
1C-Bitrix
d6core, 2021-10-16 14:21:20

How to make a selection from 2 tables using the Bitrix API?

For example, there is a table (IB) with fruits, where fruit names are stored
fruit
fruit1
fruit2

There is also a table (IB Highload, all fields linked to IB above)
fruit similar others
fruit 1 fruit5 fruit8
fruit 1 fruit3 fruit1
fruit 2 fruit6 fruit2
fruit 2 fruit4 fruit6

You need to select from the table similar for fruit 1, similar for fruit 2, others for fruit 1 and others for fruit 2

, I do this, for example, similar for fruit1

Table2::getList(array(
    'select'  => ['*'],
    'filter'  => 'фрукт1',
));

//результат массив с id, но нужно же получить имена фруктов,
//поэтому делаю второй запрос
Table1::getList(array(
    'select'  => ['*'],
    'filter'  => [ID=>'массив id похожих'],
));

//аналогичным образом делаю для остальных вариантов


in total
, if you search for information on 2 fruits - this is fruit1 and fruit2, then you get
2 getList for these fruits, and then another GetList in case similar others
As a result, there are already 6 GetList in the code. Everything works, I just want to refactor.

I have an idea to do once getList from table 2, and then just using array_filter to get the required data. Then do 1 time GetList from table 1 and bind the data by some kind of manipulation with them.

Answer the question

In order to leave comments, you need to log in

1 answer(s)
M
Mikhail Prokhorov, 2021-10-20
@pro6ka

Look here https://dev.1c-bitrix.ru/learning/course/index.php...
In fact, you need to form a query in Table1 and attach Table2 to it, then you can collect in one query from 2 tables with all required fields.

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question