Added before_destroy filter to the commentable model #38

Merged
merged 2 commits into from Dec 27, 2012

Conversation

Projects
None yet
3 participants
Contributor

xredo commented Nov 29, 2012

There was a problem when deleting the commentable model. The :dependent => :destroy clause tries to destroy all comments leading to an error because each comment also destroys its child comments, resulting in the commentable model trying to destroy an unexisting child comment.

The solution is to replace the :dependent => :destroy clause for a before_destroy filter only afecting the root comments:

ruby

before_destroy { |record| record.root_comments.destroy_all }


I experienced this malfunction with _awesome_nested_set (2.1.5)_
Xavier Redó Replaced :dependent=>destroy in commentable model for before_destroy …
…filter affecting only root_comments
31ab6ee

troex commented Nov 29, 2012

Thanks for the solution! I like this one more than another #32

Please merge!

Owner

elight commented Nov 30, 2012

Would you mind adding a test for it? Would be glad to merge then.

@elight elight added a commit that referenced this pull request Dec 27, 2012

@elight elight Merge pull request #38 from xredo/master
Added before_destroy filter to the commentable model
b021d18

@elight elight merged commit b021d18 into elight:master Dec 27, 2012

Owner

elight commented Dec 27, 2012

Thanks!

Contributor

xredo commented Dec 27, 2012

You're welcome! It's always a pleasure to collaborate. Great gem by the way ;)

niklas referenced this pull request Nov 4, 2013

Open

Feature/nested destruction #52

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment