Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Conflicts with SoftDelete when cascade delete #20

Open
ezequielgonzalez opened this issue Feb 15, 2012 · 2 comments
Open

Conflicts with SoftDelete when cascade delete #20

ezequielgonzalez opened this issue Feb 15, 2012 · 2 comments

Comments

@ezequielgonzalez
Copy link

I have a model with two objects where one of them has a composite relation with the other. Both objects uses SoftDelete, and the parent cascades the SoftDelete to dependant objects that act as Sortable.
The problem arrise when you delete one element of the parent object. I tryed adding the deleted_at field to the uniqueBy. But, as all the related objects have the same deleted_at value, when the postDelete tries to reorder all the records, it throws a constraint violation.

@daformat
Copy link

I just had the same issue, so I took a look at plugins/csDoctrineActAsSortablePlugin/lib/listener/Sortable.php, it seems the postDelete listener uses a special trick, depending on the database driver you use, to update positions on object deletion.

Fix that made the whole thing work properly for me

Look for the condition

if $this->canUpdateWithOrderBy($conn)...

Just edit the statement and replace the whole if/else block by the content of the else statement, so the postDelete behaves the same, no matter what driver you use :

    foreach ( $q->execute() as $item )
      {
        $pos = $item->get($this->_options['name'] );
        $item->set($this->_options['name'], $pos-1)->save();
      }

@bshaffer
Copy link
Owner

bshaffer commented Aug 6, 2012

Sounds like we should check for the soft delete template and skip the "UpdateWithOrderBy" if so

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

3 participants