app/models/gcp.rb
#
# Validation to check if a point does not have a duplicate x,y or lat,lon with the same map 
#
Validation to check if a point does not have a duplicate x,y or lat,lon with the same map
Validation to check if a point does not have a duplicate x y or lat lon with the same map
def unique_coordinates
    if new_record?
      if Gcp.exists?({x: x, y: y, lon: lon, lat: lat, map_id: map_id}) || ( Gcp.exists?({x: x, y: y, map_id: map_id}) || Gcp.exists?({lon: lon, lat: lat, map_id: map_id}) )
        errors.add("coordinates", "Coordinates are not unique") 
      end
    else
      if Gcp.where.not(id: id).exists?({x: x, y: y, lon: lon, lat: lat, map_id: map_id}) || ( Gcp.where.not(id: id).exists?({x: x, y: y, map_id: map_id}) || Gcp.where.not(id: id).exists?({lon: lon, lat: lat, map_id: map_id}) )
        errors.add("coordinates", "Coordinates are not unique") 
      end
    end
  end
def unique_coordinates if new_record? if Gcp . exists? ( { x : x , y : y , lon : lon , lat : lat , map_id : map_id } ) || ( Gcp . exists? ( { x : x , y : y , map_id : map_id } ) || Gcp . exists? ( { lon : lon , lat : lat , map_id : map_id } ) ) errors . add ( "coordinates" , "Coordinates are not unique" ) end else if Gcp . where . not ( id : id ) . exists? ( { x : x , y : y , lon : lon , lat : lat , map_id : map_id } ) || ( Gcp . where . not ( id : id ) . exists? ( { x : x , y : y , map_id : map_id } ) || Gcp . where . not ( id : id ) . exists? ( { lon : lon , lat : lat , map_id : map_id } ) ) errors . add ( "coordinates" , "Coordinates are not unique" ) end end end
Validation to check if a point does not have a duplicate x,y or lat,lon with the same map
Validation to check if a point does not have a duplicate x y or lat lon with the same map