Skip to content

Deletion of item in BootstrapCollectionType deletes wrong item. #49

@matejvelikonja

Description

@matejvelikonja

I encountered an issue while deleting item from BootstrapCollectionType.
When you delete one of the items using forms, the last item is always deleted instead. I've already debugged a little bit a found out that the problem is in the ReorderCollectionSubscriber.
This subscribers resets keys of the array and that's why the last item is always deleted.

For example:
I have an array:

[
    0 => "zero",
    1 => "one",
    2 => "two",
]

By using forms I delete first array element and all I have now is:

[
    1 => "one",
    2 => "two",
]

When this array is passed to the ReorderCollectionSubscriber in changes array to:

[
    0 => "one",
    1 => "two",
]

And this array is at some point passed to doctrine, doctrine does the calculation and from the array it assumes that the array element with key 2 was deleted and so the last entry is deleted from the database.

Maybe I forgot to set something but I don't know why and I don't even know why this ReorderCollectionSubscriber is doing this at all.

In my opinion this is quite a serious bug and should be addresses as soon as possible. For the current project I just commented out the adding of ReorderCollectionSubscriber to BootstrapCollectionType and the problem is gone and as far as I see everything is working normally. But not sure if this is the proper solution.

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