In my Ruby on Rails app, bike rental companies can manage all their bikes (reservations, payments etc.).
Context
I would like to offer a bike rental companies (shops) the option to implement a booking form on their own website, so they can let customers make a reservation for a bike.
- This booking form would then show
bike_categoriesof whichbikesare available for a givenarrivalanddeparturedate.
Question
After reading some documentation online, I think I should create a separate table to deal with the availability per bike_category, which would then show the the count of bikes available for the selected arrival and departure date.
=> example: between 1-1-2020 and 1-2-2010 20 bikes of bike_category "mountainbike" are available
But I'm unsure how the structure of the table should be, as a reservation is on a bike-level, which consequently belongs to a bike_category?
Code
models
class Shop < ApplicationRecord
has_many :bike_categories, dependent: :destroy
has_many :bikes, through: :bike_categories
has_many :reservations, dependent: :destroy
end
class Reservation < ApplicationRecord
belongs_to :shop
belongs_to :bike
end
class Bike < ApplicationRecord
belongs_to :bike_category
has_many :reservations, dependent: :destroy
end
class BikeCategory < ApplicationRecord
belongs_to :shop
has_many :bikes, dependent: :destroy
end