vendredi 31 juillet 2015

Rails validate only one enter per pair of db_columns

How can I validate that there can only be one enter with the same doctor_id and patient_id? (a patient can only recommend a doctor once)

class DoctorRecommendation < ActiveRecord::Base
  belongs_to :patient, :class_name => "User"
  belongs_to :doctor, :class_name => "User"

  validates :patient, presence: true
  validates :doctor, presence: true
  # does not work
  validates_uniqueness_of :recommend, scope: [:doctor_id, :patient_id]

end

Aucun commentaire:

Enregistrer un commentaire