mongoid3 - Mongoid unique model references -


i'm using mongoid 3. have simple class tour , references multiple itineraries. there way can validate each tour, itineraries' dates unique, i.e. can't have 2 itineraries of same date 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 set validation.

you can create custom validations :

class tour   has_many :itineraries   validates :check_uniqueness_of_date # line    # , part   private    def check_uniqueness_of_date     # check validation here   end end 

another stackoverflow question

rails guides


Comments

Popular posts from this blog

.htaccess - First slash is removed after domain when entering a webpage in the browser -

Automatically create pages in phpfox -

c# - Farseer ContactListener is not working -