title: .save throws an error instead of execute the else part of the conditional
body: <p>Validation for uniqueness applies to a combination of two fields. My problem is that patching a new record that does validate, throws the error <code>ActiveRecord::RecordNotUnique PG::UniqueViolation: ERROR: duplicate key value violates unique constraint</code>, rather than that it executes the <code>else</code> part of the method below. Why does it throw an error instead of execute the else part? How to change this?</p>
  
  <pre><code>def create
    first_node = Node.find_by(id: params[:first_node_id])
    second_node = Node.find_by(id: params[:second_node_id])
    link = first_node.where_first_links.build(create_params)
    if link.save
      render json: link, status: :created
    else
      render json: link, message: "unable", status: :bad_request
    end
  end
  </code></pre>
  
  <p>In the migration file:</p>
  
  <pre><code>add_index :links, [:first_node_id, :second_node_id], unique: true
  </code></pre>
  
  <p>The model validation:</p>
  
  <pre><code>before_save  :order_nodes
  validates :first_node_id,    presence: true
  validates :second_node_id,   presence: true
  validates :first_node_id,    uniqueness: { scope: :second_node_id } 
  
  def order_nodes
    if first_node_id &gt; second_node_id
      first = first_node_id
      second = second_node_id
      self.first_node_id  = second
      self.second_node_id = first
      if direction == '0'
        self.direction = 1
      elsif direction == '1'
        self.direction = 0
      end
    end
  end
  </code></pre>