A
A
Anton Shelestov2017-10-02 12:56:20
1C-Bitrix
Anton Shelestov, 2017-10-02 12:56:20

Are there setters and getters in the Bitrix ORM?

Hello people.
Such a question:
Is there an ORM

class RbUrlListTable extends DataManager
{
    public static function getFilePath()
    {
        return __FILE__;
    }

    public static function getTableName()
    {
        return 'rb_url_lists';
    }

    public static function getMap()
    {
        return array(
            new IntegerField('ID', array(
                'primary' => true,
                'autocomplete' => true,
            )),
            new StringField('TITLE', array(
                'required' => true,
            )),
            new StringField('ALIAS', array(
                'required' => true,
            )),
            new TextField('PARAMS', array(
                'required' => true,
            )),
            new TextField('SETTINGS', array(
                'required' => true,
            )),
        );
    }
}

the PARAMS field contains a json string.
Is it possible to create a getter that will create a new element such as TYPE with a value from PARAMS->TYPE?

Answer the question

In order to leave comments, you need to log in

2 answer(s)
A
Alexander Filippenko, 2017-10-02
@alexfilus

In standard tables, I often see that the field contains a serialized array, and when requested without additional processing, it is returned deserialized. You can try to use it. But I did not check how it works in my tables.
Or write your own wrapper that will unpack json. Although a dubious exercise, an object is returned, not an array.
You can override getRow and use it.

A
Andrey Nikolaev, 2017-10-03
@gromdron

A very interesting task. If you need to operate only after receiving the data, then the "Format Values"
mechanism from the ORM documentation is perfect for you . In this case, you can use serialization or json at your discretion (I recommend serialization - it is more native and there is a chance that it will work in the performance module). If you have MySQL higher than 5.7 version, you can add several Expression fields and extract keys from JSON as well as fields. Until we tried this option, our hands did not reach.

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question