X-Git-Url: https://irasnyder.com/gitweb/?a=blobdiff_plain;ds=sidebyside;f=app%2Fmodels%2Fgame.rb;h=a2d324a5f74f3e5156e9d6e46756d59a1ba8badf;hb=50e2ce05003eb4a56d1daa8e030a2f477aeb59bc;hp=6c6b59be09b563ca2504fddb445ac6079220734b;hpb=bf5c679032a167a9eeb4aa16284cd5dd2426a12a;p=cs356-p2-videostore.git diff --git a/app/models/game.rb b/app/models/game.rb index 6c6b59b..a2d324a 100644 --- a/app/models/game.rb +++ b/app/models/game.rb @@ -1,6 +1,17 @@ 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 + GameGenre.find_by_id(game_genre_id) + end + + def platform + GamePlatform.find_by_id(game_platform_id) + end def calculated_price # FIXME: generate this based on day of week, newrelease @@ -24,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