O
O
Oleg Mifle2016-10-26 11:50:48
1C-Bitrix
Oleg Mifle, 2016-10-26 11:50:48

How to filter custom properties in bitrix ORM?

I am trying to execute the following query

$res = Bitrix\Iblock\ElementTable::getList(array(
            'select' => array('ID', 'CODE'),
            'filter' => array(
                '=IBLOCK_ID' => 9,
                '=ACTIVE'=>'Y',
                '!PROPERTY_OWN' => false
                )
            )
        );

The script then fails with the following error:

Unknown field definition `PROPERTY_OWN` (PROPERTY_OWN) for Element Entity. (100)

It seems to be understandable, user properties are stored in another table, but then how to make a selection?

Answer the question

In order to leave comments, you need to log in

1 answer(s)
O
Oleg Maksimenko, 2016-10-27
@OlegMifle

Not out of the box yet. You can compile an entity with properties on the fly and add it to the selection through the runtime section in the getlist.
Example (for properties in a separate table):

//<?php

\Bitrix\Main\Loader::includeModule('iblock');

$iblockId = 155;

$entityPropsSingle = Bitrix\Main\Entity\Base::compileEntity(
    sprintf('PROPS_SINGLE_%s', $iblockId),
    [
        'IBLOCK_ELEMENT_ID' => ['data_type' => 'integer'],
        'PROPERTY_1020' => ['data_type' => 'integer'],
    ],
    [
        'table_name' => sprintf('b_iblock_element_prop_s%s', $iblockId),
    ]
);

\Bitrix\Main\Application::getConnection()->startTracker();

$result = \Bitrix\Iblock\ElementTable::getList([
    'select' => [
        'ID',
        'NAME',
        'PROPS_SINGLE.*',
    ],
    'filter' => [
        '>PROPS_SINGLE.PROPERTY_1020' => 0,
    ],
    'order' => [
        'PROPS_SINGLE.PROPERTY_1020' => 'ASC',
    ],
    'runtime' => [
        'PROPS_SINGLE' => [
            'data_type' => $entityPropsSingle->getDataClass(),
            'reference' => [
                '=this.ID' => 'ref.IBLOCK_ELEMENT_ID'
            ],
            'join_type' => 'inner'
        ],
    ],
]);

// Можно смотреть сформированный запрос
echo '<pre>', $result->getTrackerQuery()->getSql(), '</pre>';

echo '<pre>';print_r($result->fetchAll());echo '</pre>';

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question