-
Type: Improvement
-
Resolution: Unresolved
-
Priority: Major - P3
-
None
-
Affects Version/s: 7.0.5
-
Component/s: Associations
-
Environment:Ruby 2.5.0, Rails 6.0.0
Given the minimal example
class ShoppingCart include Mongoid::Document embeds_many :items end class Item include Mongoid::Document embedded_in :shopping_cart end
when I create a cart with an item and then remove the item, changed? will still be false:
2.5.0 :001 > cart = ShoppingCart.new => #<ShoppingCart _id: 5da45df1a8f8434462c1ce27, > 2.5.0 :002 > item = cart.items.new => #<Item _id: 5da45dfaa8f8434462c1ce28, > 2.5.0 :003 > cart.save => true 2.5.0 :004 > cart.items = [] => [] 2.5.0 :005 > cart.changed? => false
This is especially problematic when using Mongoid::Timestamps, because cart.items.last.delete will $pull the item, but *not* $set the updated_at timestamp