sortable bug fix

master
Константин 2023-09-07 16:30:47 +03:00
parent 41a7cd65cf
commit 308a84f889
1 changed files with 2 additions and 2 deletions

View File

@ -38,12 +38,12 @@ trait HasObjectsTrait {
}
public function attachObject(NirObject $object, $ord = null, $group = null) {
$ord = ($ord === null) ? $this->getMaxOrd($group) : $ord;
$ord = ($ord === null) ? $this->getMaxObjectOrd($group) : $ord;
$this->moveObjectsSet('forward', $ord, null, $group);
$this->objects()->attach($object->id, ['ord' => $ord ?? 0, 'group' => $group ?? 'default']);
}
public function getMaxOrd($group = null): int {
public function getMaxObjectOrd($group = null): int {
$res = $this->objectsByGroup($group)->max('ord');
return ($res !== null) ? ($res + 1) : 0;
}