Ruby-on-rails – rails – Comment W ACTS_AS_NESTED_SET – Remove the destruction data when deleting related records

I have the following models:

class Group  has_many :threads, :dependent => :destroy

class Thread has_many :comments, :as => :commentable, :dependent => :destroy

class Comment belongs_to :commentable, :polymorphic => true
acts_as_nested_set

The problem I have is that when the user deletes a group, all types of comments are destroyed Or delete. I looked at the log and this is what happened:

Comment Load (0.8ms) SELECT "comments".* FROM "comments" WHERE ("comments" .commentable_id = 101 AND "comments".commentable_type ='Thread') ORDER BY comments.created_at DESC
AREL (0.9ms) DELETE FROM "comments" WHERE ("comments"."lft"> 649 AND "comments" ."rgt" <650)
AREL (0.4ms) UPDATE "comments" SET "lft" = ("lft"-2) WHERE ("lft"> 650)
AREL (0.5ms) UPDATE "comments" SET "rgt" = ("rgt"-2) WHERE ("rgt"> 650)
AREL (0.2ms) DELETE FROM "comments" WHERE ("comments"."id" = 381)< br />AREL (0.4ms) DE LETE FROM "comments" WHERE ("comments"."lft"> 645 AND "comments"."rgt" <646)
AREL (0.4ms) UPDATE "comments" SET "lft" = ("lft"- 2) WHERE ("lft"> 646)
AREL (0.4ms) UPDATE "comments" SET "rgt" = ("rgt"-2) WHERE ("rgt"> 646)
AREL (0.2 ms) DELETE FROM "comments" WHERE ("comments"."id" = 380)
AREL (0.3ms) DELETE FROM "comments" WHERE ("comments"."lft"> 648 AND "comments"." rgt" <651)
AREL (0.3ms) UPDATE "comments" SET "lft" = ("lft"-4) WHERE ("lft"> 651)
AREL (0.3ms) UPDATE "comments "SET "rgt" = ("rgt"-4) WHERE ("rgt"> 651)
AREL (0.2ms) DELETE FROM "comments" WHERE ("comments"."id" = 379)
AREL (0.3ms) DELETE FROM "comments" WHERE ("comments"."lft"> 644 AND "comments"."rgt" <647)
AREL (0.4ms) UPDATE "comments" SET "lft" = ("lft"-4) WHERE ("lft"> 647)
AREL (0.4ms) UPDATE "comments" SET "rgt" = ("rgt"-4) WHERE ("rgt"> 647)< br />AREL (0.2ms) DELETE FROM "comments" WHERE ("comments"."id" = 378)
AREL (0.4ms) DELETE FROM "comments" WHERE ("comments"."lft"> 642 AND "comments"."rgt" <643)
AREL (0.8ms) UPDATE "comments" SET "lft" = ("lft"- 2) WHERE ("lft"> 643)
AREL (0.4ms) UPDATE "comments" SET "rgt" = ("rgt"-2) WHERE ("rgt"> 643)
AREL (0.2 ms) DELETE FROM "comments" WHERE ("comments"."id" = 377)
AREL (0.7ms) DELETE FROM "comments" WHERE ("comments"."lft"> 641 AND "comments"." rgt" <652)
AREL (0.9ms) UPDATE "comments" SET "lft" = ("lft"-12) WHERE ("lft"> 652)
AREL (0.9ms) UPDATE "comments "SET "rgt" = ("rgt"-12) WHERE ("rgt"> 652)
AREL (0.3ms) DELETE FROM "comments" WHERE ("comments"."id" = 376)
AREL (0.4ms) DELETE FROM "threads" WHERE ("threads"."id" = 101)
AREL (0.4ms) DELETE FROM "groups" WHERE ("groups"."id" = 57)< /pre>

Is this behavior a normal nested behavior? I hope there is only DELETE FROM COMMENTS, where Comment.id = XXXX. But instead, all of this is going on, and the comment record is breaking.

Has anyone seen this?

Thank you

Update w to prevent deep nesting content:

after_save :ensure_max_nestedset_level
def ensure_max_nestedset_level< br /> if self.level> 2
self.move_to_child_of(parent.parent)
end
end

< /div>

This shouldn’t break the record. When deleting a node, you must trim the tree. The comments in acts_as_nested_set say

"both adding and removing an entry require a full table write."

this before destroy method in acts_as_nested_set tries to reorganize the table when deleting the "comment" record. This is normal behavior.

I have the following models:

< p>

class Group  has_many :threads, :dependent => :destroy

class Thread has_many :comments, :as => :commentable, :dependent => :destroy

class Comment belongs_to :commentable, :polymorphic => true
acts_as_nested_set< /pre>

The problem I encountered is when a user deletes a When a group, all types of comments were destroyed or deleted. I looked at the log and this is what happened:

Comment Load (0.8ms) SELECT "comments" .* FROM "comments" WHERE ("comments".commentable_id = 101 AND "comments".commentable_type ='Thread') ORDER BY comments.created_at DESC
AREL (0.9ms) DELETE FROM "comments" WHERE ("comments "."lft"> 649 AND "comments"."rgt" <650)
AREL (0.4ms) UPDATE "comments" SET "lft" = ("lft"-2) WHERE ("lft"> 650 )
AREL (0.5ms) UPDATE "comments" SET "rgt" = ("rgt"-2) WHERE ("rgt"> 650)
AREL (0.2ms) DELETE FROM "comments" WHERE ( "comments"."id" = 381)
AREL (0.4ms) DELETE FROM "comments" WHERE ("comments"."lft"> 645 AND "comments"."rgt" <646)
AREL (0.4ms) UPDATE "comments" SET "lft" = ("lft"-2) WHERE ("lft"> 646)
AREL (0.4ms) UPDATE "comments" SET "rgt" = ("rgt "-2) WHERE ("rgt"> 646)
AREL (0.2ms) DELETE FROM "comments" WHERE ("comments"."id" = 380)
AREL (0.3ms) DELETE FROM" comments" WHERE ("comments"."lft"> 648 AND "comments"."rgt" <651)
AREL (0.3ms) UPDATE "comments" SET "lft" = ("lft"-4) WHERE ("lft"> 651)
AREL (0.3ms) UPDATE "comments" SET "rgt" = ( "rgt"-4) WHERE ("rgt"> 651)
AREL (0.2ms) DELETE FROM "comments" WHERE ("comments"."id" = 379)
AREL (0.3ms) DELETE FROM "comments" WHERE ("comments"."lft"> 644 AND "comments"."rgt" <647)
AREL (0.4ms) UPDATE "comments" SET "lft" = ("lft"-4 ) WHERE ("lft"> 647)
AREL (0.4ms) UPDATE "comments" SET "rgt" = ("rgt"-4) WHERE ("rgt"> 647)
AREL (0.2ms) ) DELETE FROM "comments" WHERE ("comments"."id" = 378)
AREL (0.4ms) DELETE FROM "comments" WHERE ("comments"."lft"> 642 AND "comments"."rgt "<643)
AREL (0.8ms) UPDATE "comments" SET "lft" = ("lft"-2) WHERE ("lft"> 643)
AREL (0.4ms) UPDATE "comments" SET "rgt" = ("rgt"-2) WHERE ("rgt"> 643)
AREL (0.2ms) DELETE FROM "comments" WHERE ("comments"."id" = 377)
AREL (0.7ms) DELETE FROM "comments" WHERE ("comments"."lft"> 641 AND "comments"."rgt" <652)AREL (0.9ms) UPDATE "comments" SET "lft" = ("lft"-12) WHERE ("lft"> 652)
AREL (0.9ms) UPDATE "comments" SET "rgt" = ("rgt"-12) WHERE ("rgt"> 652)
AREL (0.3ms) DELETE FROM "comments" WHERE ("comments"."id" = 376)
AREL (0.4ms) DELETE FROM "threads" WHERE ("threads"."id" = 101)
AREL (0.4ms) DELETE FROM "groups" WHERE ("groups"."id" = 57)

Is this behavior the normal behavior of nesting? I hope there is only DELETE FROM COMMENTS, where Comment.id = XXXX. But instead, all of this is going on, and the comment record is breaking.

Has anyone seen this?

Thank you

Update the content used to prevent deep nesting:

after_save :ensure_max_nestedset_level
def ensure_max_nestedset_level< br /> if self.level> 2
self.move_to_child_of(parent.parent)
end
end

this Records should not be broken. When deleting nodes, the tree must be trimmed. The comments in acts_as_nested_set say

"both adding and removing an entry require a full table write."

this before destroy method in acts_as_nested_set When reorganizing the table, this is normal behavior.

WordPress database error: [Table 'yf99682.wp_s6mz6tyggq_comments' doesn't exist]
SELECT SQL_CALC_FOUND_ROWS wp_s6mz6tyggq_comments.comment_ID FROM wp_s6mz6tyggq_comments WHERE ( comment_approved = '1' ) AND comment_post_ID = 3301 ORDER BY wp_s6mz6tyggq_comments.comment_date_gmt ASC, wp_s6mz6tyggq_comments.comment_ID ASC

Leave a Comment

Your email address will not be published.