Skip to content

Commit

Permalink
Minor adjustment to model association validation
Browse files Browse the repository at this point in the history
  • Loading branch information
fmanimashaun committed Feb 15, 2024
1 parent 2359282 commit 8c316b2
Show file tree
Hide file tree
Showing 3 changed files with 3 additions and 1 deletion.
1 change: 1 addition & 0 deletions app/models/car_detail.rb
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
class CarDetail < ApplicationRecord
belongs_to :car
belongs_to :engine_type

validates :horsepower, :torque, numericality: { only_integer: true, greater_than: 0 }
validates :fuel_economy, :seating_capacity, :cargo_space, :infotainment_system, :safety_rating, :tech_features,
:special_features, presence: true
Expand Down
1 change: 1 addition & 0 deletions app/models/engine_type.rb
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
class EngineType < ApplicationRecord
has_many :car_details, dependent: :destroy

validates :name, presence: true, length: { maximum: 255 }
end
2 changes: 1 addition & 1 deletion app/models/reservation.rb
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@ class Reservation < ApplicationRecord
belongs_to :car
belongs_to :user

validates :date, :car_id, :city_id, :user_id, presence: true
validates :date, presence: true
validate :date_cannot_be_in_the_past

def date_cannot_be_in_the_past
Expand Down

0 comments on commit 8c316b2

Please sign in to comment.