twill icon indicating copy to clipboard operation
twill copied to clipboard

[2.x] Set position on multi selects

Open antonioribeiro opened this issue 1 year ago • 3 comments

Description

We have a model with a bunch of different tags:

Screenshot 2023-02-27 at 12 27 54

That are using multi-selects

$this->updateMultiSelect($object, $fields, 'countries');

One of our frontend pages needs to use the first tag of each of these fields. So I I tried to get the ordered:

public function countries()
{
    return $this->belongsToMany(Country::class, 'analysis_country', 'analysis_id', 'country_id')
                ->orderBy('analysis_country.position');
}

Just find that the position field is not being filled up, they are all null, so this PR is intended to do it automatically, unless there's already a position being set by the application.

Related Issues

antonioribeiro avatar Feb 27 '23 11:02 antonioribeiro

CLA assistant check
All committers have signed the CLA.

CLAassistant avatar Feb 27 '23 11:02 CLAassistant

  • The updateMultiSelect method was changed to support the new pivot fields.
  • If an error occurs, maybe because the pivot table doesn't have a 'position' column, we will just keep the old implementation and sync without any extra parameters (the way it used to work).

what-the-diff[bot] avatar Feb 27 '23 11:02 what-the-diff[bot]

CLA assistant is in trouble... :(

Screenshot 2023-02-27 at 14 20 53

antonioribeiro avatar Feb 27 '23 13:02 antonioribeiro