X-Git-Url: https://irasnyder.com/gitweb/?a=blobdiff_plain;ds=sidebyside;f=app%2Fmodels%2Fgame.rb;h=a2d324a5f74f3e5156e9d6e46756d59a1ba8badf;hb=50e2ce05003eb4a56d1daa8e030a2f477aeb59bc;hp=f2e627c765ab12e21bcc514aa5c2c7603dda42af;hpb=e4597521e3a7365f86731f7d69643cb1067acb5e;p=cs356-p2-videostore.git diff --git a/app/models/game.rb b/app/models/game.rb index f2e627c..a2d324a 100644 --- a/app/models/game.rb +++ b/app/models/game.rb @@ -1,16 +1,16 @@ class Game < Rentable - has_many :game_genres, :through => Gamegenre - has_many :gameplatforms, :through => Gameplatform + has_many :game_genres + has_many :game_platforms - validates_presence_of :game_genre - validates_presence_of :platform + 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 game_platform - return Gameplatform.find(platform).name + def platform + GamePlatform.find_by_id(game_platform_id) end def calculated_price @@ -35,12 +35,10 @@ class Game < Rentable return Time.now.advance(:days => period).to_date end - def genre_name - Gamegenre.find_by_id(game_genre).name - end - - def platform_name - Gameplatform.find_by_id(platform).name + 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