Topic: Problem with switching values using join model

Hi,
I have a join model with columns: frame_id, panel_id and sequence:

class FramePanel < ActiveRecord::Base
  belongs_to :frame
  belongs_to :panel
  
  validates_uniqueness_of :panel_id, :scope => [:frame_id]  # check against adding same panel
  validates_uniqueness_of :sequence, :scope => [:frame_id] # check against same sequence
end

My 'frame' has many 'panels' set in an ordered sequence and I have validations to check against adding same 'panel' to the 'frame' or 'panel' with same 'sequence' number.

The problem appears when I want to switch positions of eg. two panels using update_attributes method. 'Sequence' validator gives me an error that this 'sequence' number has already been taken.

I tried commenting out the 'sequence' validator and implementing only memory check against same sequence number but then I get
ActiveRecord::RecordNotUnique exception because of duplicate key in database.

Any help would be appreciated. Thanks in advance.