-
Type: Bug
-
Resolution: Fixed
-
Priority: Major - P3
-
Affects Version/s: 7.0.12, 7.2.2
-
Component/s: Associations
-
None
-
Environment:Rails 5.2.4.4
Mongoid 7.0.12
-
Minor Change
Given those classes :
class Article include Mongoid::Document has_many :comments end class Comment include Mongoid::Document belongs_to :article end
When I create a comment with an article, the number of comments in the article isn't updated after destroy_all. The clear does the job.
article = Article.create comment = Comment.create(article: article) pp article.comments.length # => 1 article.comments.destroy_all pp article.comments.length # => Continues to give 1 and should give 0 article.comments.clear pp article.comments.length # => 0
If I add article.reload after the creation of the comment the behavior is correct. This problem isn't in Mongoid 6.2.
delete_all also currently does not clear the association - this may be the correct/desired behavior and when this ticket is worked on tests should be added to this effect if there aren't already.