Skip to content

moveToStart updates wrong rows #170

@quelo83

Description

@quelo83

Hi,
the method "moveToStart" doesn't seem to work well. It increments all rows except the current model and this is not correct.
The current code is:

$this->$orderColumnName = $firstModel->$orderColumnName;
$this->save();

$this->buildSortQuery()->where($this->getKeyName(), '!=', $this->getKey())->increment($orderColumnName);

If I'm not wrong, the query should have another where clause to scope and increment only the previous rows, something like this:

$previousOrder = $this->$orderColumnName;

$this->$orderColumnName = $firstModel->$orderColumnName;
$this->save();

$this->buildSortQuery()
    ->where($this->getKeyName(), '!=', $this->getKey())
    ->where($this->getKeyName(), '<', $previousOrder)
    ->increment($orderColumnName);

Please, let me know if I'm missing something.

Thanks in advance!

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions