Assign Tailor ManyToMany relation in PHP

Hi there,
I’m working on the big data sample for products and parts - there are thousands of those and I need the functionality for assigning many parts to many products. Current entries have the option of different display modes, however only displayMode: relation coves ManyToMany scenario. I cannot provide the list with tickboxes of over 2 thousand non-sorted entries that cannot even be ctrl+f for…
Screenshot 2023-03-03 122858
My plan would be to create custom protected page that would allow me to edit products with the usage of bootstrap multi-selectpickers, however I’m unable to find any way of doing the ‘$product->makeRelation()’ part:

function onProductSelect() {
    $product = Tailor\Models\EntryRecord::inSection('Products\Product')->find(post('title'));
    $parts = post('parts');
    foreach ($parts as $part)
    {
        $actualPart = Tailor\Models\EntryRecord::inSection('Products\Parts\Part')->find($part);

        $product->makeRelation($actualPart);
        $product->update();
    }
}

Any help will be much appreciated! I was trying to go through the vendor files looking for the way that tailor is handling the entry ‘save’ button, however, didn’t find anything useful.

I’ve managed to hard-code it (project-specific scenario; assignment of those is one-time action), however, this would be great functionality for the future updates as current list doesn’t work well with 100+ entries. Even alphabetical sorting would help a lot!

If anyone ever finds it - this isn’t a good solution, but works fine for my specific scenario:

{{ form_ajax('onProductSelect') }}

    <div class="col-lg-6">
    <label for="title">Title</label><br/>
    <select name="title">
        {% for product in products | sort((a, b) => a.title <=> b.title) %}
            <option value="{{ product.id }}">{{ product.title }}</option>
        {% endfor %}
    </select>
    </div>

    <div class="col-lg-6">
    <select type="text" class="form-control selectpicker" placeholder="Parts" name="parts[]" multiple data-live-search="true" data-selected-text-format="count" title="Part">
        {% for part in parts | sort((a, b) => a.title <=> b.title) %}
            <option value="{{ part.id }}">{{ part.title }}</option>
        {% endfor %}
    </select>
    </div>
    <div class="submit-div"><button class="cta-btn" type="submit">Submit</button></div>

{{ form_close() }}

and in PHP:

function onProductSelect() {
    $product = Tailor\Models\EntryRecord::inSection('Products\Product')->find(post('title'));
    $parts = post('parts');
    if($parts)
    {
        foreach ($parts as $part)
        {
            $actualPart = Tailor\Models\EntryRecord::inSection('Products\Parts\Part')->find($part);
            DB::insert('insert into ManyToManyRelationshipTailorTable_YouHaveToFindYours (parent_id, relation_id, relation_type, field_name, site_id) values (?, ?, ?, ?, ?)', [$product->id, $actualPart->id, 'Tailor\\Models\\EntryRecord@TailorHash_YouHaveToFindYours', 'parts', NULL]);
        }
    }