Complex validation validates_uniqueness_of

hi, i want to validate the uniquenes of a field (in the same model),
based on different circumstances, i have try with this:

validates_uniqueness_of :event_description_id, :scope => [ :deleted,
:com_unit_id, :eventable_type, :eventable_id ], :if =>
:unique_for_bonded?
validates_uniqueness_of :event_description_id, :scope => [ :deleted,
:com_group_id ], :if => :unique_for_shared?
validates_uniqueness_of :event_description_id, :scope => [ :deleted,
:com_group_id, :com_unit_id ], :if => :unique_for_com_unit?

def unique_for_bonded?
bonded == true
end
def unique_for_shared?
shared == true and bonded == nil
end
def unique_for_com_unit?
shared == false and bonded == nil
end

but don’ validate correctly, any idea?

This forum is not affiliated to the Ruby language, Ruby on Rails framework, nor any Ruby applications discussed here.

| Privacy Policy | Terms of Service | Remote Ruby Jobs