This forum has moved to a new location and is in read-only mode. Please visit talk.octobercms.com to access the new location.

kollis
kollis

I have a problem with sorting relation field in belongsToMany relation:

public $belongsToMany = [
    'attributes' => [
        'Models\Attribute',
        'table' => 'attributeset_attribute',
        'order' => ['is_configurable desc', 'sort_order', 'name'],
        'pivot' => ['is_configurable', 'sort_order'],
        'pivotModel' => 'Models\AttributesetAttributePivot'
    ]
];

Everything works great, but when I click on the "Link" button, I recieve an error "1054 Unknown column 'is_configurable' in 'order clause'". Of course, I do not need ordering by pivot field, when linking an attribute. I tried changing the order in the controller:

public function onRelationButtonLink()
{
    Attributeset::extend(function($model) {
        $model->belongsToMany['attributes']['order'] = array('name');
    });

    return $this->asExtension('RelationController')->onRelationButtonLink();
}

After this I was able to open "Link" dialog, but when I tried to sort or search for some records, I received the same error. Is it possible to set different sorting criteria for the relation field list and "Link" form (include search)?

joshwordshop51728
joshwordshop51728

Did you ever figure this out, I've got exactly the same problem and I can't just drop the order to make the add function work

Flynsarmy
Flynsarmy

Creating two separate relationships could work. One with the sort order and one without.

1-3 of 3

You cannot edit posts or make replies: the forum has moved to talk.octobercms.com.