Fix the late fee calculations
[cs356-p2-videostore.git] / app / models / game.rb
index 15bf8e0..a2d324a 100644 (file)
@@ -1,9 +1,16 @@
 class Game < Rentable
-  validates_presence_of :game_genre
-  validates_presence_of :platform
+  has_many :game_genres
+  has_many :game_platforms
+
+  validates_presence_of :game_genre_id
+  validates_presence_of :game_platform_id
 
   def genre
-    return Gamegenre.find(game_genre).name
+    GameGenre.find_by_id(game_genre_id)
+  end
+
+  def platform
+    GamePlatform.find_by_id(game_platform_id)
   end
 
   def calculated_price
@@ -28,4 +35,10 @@ class Game < Rentable
     return Time.now.advance(:days => period).to_date
   end
 
+  protected
+  def validate
+    errors.add(:game_genre_id, "does not exist in the database") if genre.nil?
+    errors.add(:game_platform_id, "does not exist in the database") if platform.nil?
+  end
+
 end