I am trying to insert a row into the join table, that I created in this migration (with timestamp):
class CreateUserNewsItemJoinTable < ActiveRecord::Migration
  def change
    create_join_table :users, :news_items do |t|
      t.timestamps
    end
    add_index :news_items_users, [:user_id, :news_item_id], unique: true
  end
end
This is how I insert NewsItem into User:
@user.news_items << @news_item
The first time, it was inserted successfully. But if I insert the same record again, it shows UniqueViolation.
How can I make the identical insert, to update timestamp, instead of throwing UniqueViolation error?
 
     
    