class Cart
include Mongoid::Document
embeds_many :cart_items
def calculate_prices
# Set some fields
end
def remove_item(item)
# what goes here?
calculate_prices
save
end
end
class CartItem
include Mongoid::Document
embedded_in :cart
end
我希望remove_item
从购物车中自动删除购物车项目,并将一些新价格设置为购物update
车集合。
那可能吗?也许有一些 API 可以将嵌入的项目标记为销毁然后保存购物车?