I have a person model which embeds_many
addresses.
Is there a way to always clear embedded relationship when updating? For example, If I send a complete representation of a person, including addresses, I want to replace existing addresses rather than appending them.
My temp fix is a before_save
callback which clear out all addresses
class Person
include Mongoid::Document
embeds_many :addresses
before_save :clear_addresses!
def clear_addresses!
self.unset(:addresses)
end
end