Answer the question
In order to leave comments, you need to log in
Bitrix ORM: get one of the linked table records?
Hello.
Something does not work for me to make a slightly non-standard request through the ORM. please help
For example, there is a table of orders b_order (OrderTable)
B there is a table of logs, for example, logs (LogTable)
The logs table can have many records for each order, and there may also be no records
I need to get a list of orders linked to the last record logs table (if any)
$query = OrderTable::query()
->registerRuntimeField('LOG', array(
'data_type'=> LogTable::class,
'reference' => [
'=this.ID' => 'ref.ORDER_ID',
]
))
;
->registerRuntimeField('LAST_LOG_ENTITY', [
'data_type'=>'integer',
'expression' => ['MAX(%s)', 'LOG.ID']
])
->where('LAST_LOG_ENTITY', '!=', false)
Answer the question
In order to leave comments, you need to log in
And you do not consider a variant with two requests.?
Select orders, collect IDs, select logs with maximum IDs linked to collected orders. If logs has an index by ORDER_ID, then the query will be very fast.
Try to use complex logic with a flag to eliminate duplicates "LOGIC"=>"OR"
Didn't find what you were looking for?
Ask your questionAsk a Question
731 491 924 answers to any question