Skip to content

Incorrectly filled _lft _rgt when changed parent_id for 2+ models #626

@Nhemas

Description

@Nhemas

As example I receive 2 requests, which must change parent_id of 2 models. Prev and new parent_id are different but same for both models. But sometimes i see when _lft and _rgt filled incorrectly. There are 3 possible outcomes: 1. both models have same lft rgt 2. both parents rgt lft cross each other, example: 1-210, 200-211 3. everything ok
It seems like ordinary problem with parallel queries, but somehow i cant resolve it. I tried: 1. add lock table 2. set isolation level to serializable 3. add ->fixTree() at the start and the end of transaction 4. all together
I think the problem happens here. $inputData has only parent_id.

DB::transaction(function () use ($inputData, $model) {
    $model->fill($inputData);
    $model->save();
}

Cant understand why transaction didnt help, I dont think model additionally changes somewhere else

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions