A
A
Alexey2017-03-15 16:32:23
ORM
Alexey, 2017-03-15 16:32:23

How to get a value from several entities in Bitrix using ORM?

Good afternoon!
I faced the task of fetching values ​​from two different entities (deals and contacts), but I can't figure out how to do it.
An example of extracting data from a deal:

use Bitrix\Crm\DealTable;
use Bitrix\Crm\ContactTable;

$arDeal = DealTable::getList(array(
  'select' => array('CONTACT_ID'),
  'filter' => array('CREATED_BY_ID'=>1)
))->fetchAll();

I don't know how to add REFERAL value (source) from the contacts entity to the $arDeal array in one request. Thank you in advance.

Answer the question

In order to leave comments, you need to log in

1 answer(s)
R
Roman Gritsuk, 2017-03-15
@MrSen

Here you can read about the relationship between ORM entities.
If the entities you're asking about are related, then this is pretty easy.
Let's say this is how the field is described for which there is a connection between the Book entity and Author inside the BookTable class:

new Entity\ReferenceField(
    'AUTHOR',
    'SomePartner\MyBooksCatalog\Author',
    array('=this.AUTHOR_ID' => 'ref.ID'),
    array('join_type' => 'LEFT')
)

then to select any field from the author entity, add Author.<Field code> to getList. for example like this:
BookTable::getList(array(
    'select' => array(
        'TITLE',
        'AUTHOR_NAME' => 'AUTHOR.NAME',
        'AUTHOR_LAST_NAME' => 'AUTHOR.LAST_NAME'
    )
));

The example is taken from the article linked above.

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question