Add real, selectable videogenres
[cs356-p2-videostore.git] / app / models / coitem.rb
1 class Coitem < ActiveRecord::Base
2   belongs_to :customer
3   belongs_to :rentable
4
5   # Make sure the user typed in the ids
6   validates_presence_of :customer_id
7   validates_presence_of :rentable_id
8
9   # Make sure the user typed in numbers
10   validates_numericality_of :customer_id
11   validates_numericality_of :rentable_id
12
13   # Make sure this rentable was not already checked out
14   validates_uniqueness_of :rentable_id
15
16   # Make sure the associated rentable and customer are valid and exist
17   validates_associated :customer
18   validates_associated :rentable
19
20   protected
21   def validate
22     errors.add(:customer_id, "does not exist is the database") if customer.nil?
23     errors.add(:rentable_id, "does not exist in the database") if rentable.nil?
24   end
25 end