twill
twill copied to clipboard
[2.x] Set position on multi selects
Description
We have a model with a bunch of different tags:

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
- 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).
CLA assistant is in trouble... :(
