Validates_uniqueness_of fails on Arrays

validates_uniqueness_of fails to recognise unique arrays.

I think this is because ActiveRecord calls serialize on a property when
it is an Array but validates_uniqueness_of is comparing the original
property with the serialized version.

Anthony G.

This workaround appears to work

validates_uniqueness_of :members, :scope => ‘band_id’, :message =>
“This line up already exists”

before_validation :serialize_members
after_validation :deserialize_members

def serialize_members
self.members.sort!
self.members = self.members.to_yaml
end

def deserialize_members
self.members = YAML::load(self.members)
end

For the moment I’ve added these two lines (st 552) to validations.rb

      if condition_params[0].instance_of? Array
        condition_params[0] = condition_params[0].to_yaml
      end

Which appears to work but I haven’t tested.

Tony Green