diff --git a/lib/replicate/active_record.rb b/lib/replicate/active_record.rb index 6acdcee..13d4b89 100644 --- a/lib/replicate/active_record.rb +++ b/lib/replicate/active_record.rb @@ -280,7 +280,11 @@ def create_or_update_replicant(instance, attributes) # write replicated attributes to the instance attributes.each do |key, value| next if key == primary_key and not replicate_id - instance.send :write_attribute, key, value + # Don't write the attribute with the same value as before to avoid + # triggering unique key constraints + unless instance.send(:read_attribute, key) == value + instance.send :write_attribute, key, value + end end # save the instance bypassing all callbacks and validations