Fix the late fee calculations
[cs356-p2-videostore.git] / app / models / video.rb
index 52344e1..fd5d22f 100644 (file)
@@ -1,10 +1,18 @@
 class Video < Rentable
   has_many :video_genres
-  has_many :medias
+  has_many :video_medias
 
   validates_presence_of :director
-  validates_presence_of :video_genre
-  validates_presence_of :media
+  validates_presence_of :video_genre_id
+  validates_presence_of :video_media_id
+
+  def genre
+    VideoGenre.find_by_id(video_genre_id)
+  end
+
+  def media
+    VideoMedia.find_by_id(video_media_id)
+  end
 
   def calculated_price
     # FIXME: generate this based on day of week, newrelease
@@ -30,7 +38,7 @@ class Video < Rentable
 
   protected
   def validate
-    errors.add(:video_genre, "does not exist in the database") if video_genre.nil?
-    errors.add(:media, "does not exist in the database") if media.nil?
+    errors.add(:video_genre_id, "does not exist in the database") if genre.nil?
+    errors.add(:video_media_id, "does not exist in the database") if media.nil?
   end
 end