I'm using Mongoid 3. I have a simple class Tour
and references multiple Itineraries
. Is there a way that I can validate that for each tour, the itineraries' dates are unique, i.e. I can't have 2 itineraries of the same date for a single tour.
class Tour
has_many :itineraries
end
class Itinerary
field :date, :type => Date
validates :date, :presence => true
index({date: 1})
belongs_to :tour
end
I'm not sure how to set up the validation.