Based on your description, here's a list of ActiveRecord models you'll need for your Airbnb-like marketplace application:
- User
- Role
- Service
- Booking
- Review
Now, let's define the models along with their associations:
# app/models/user.rb
class User < ApplicationRecord
has_many :services, foreign_key: :supplier_id
has_many :bookings, foreign_key: :customer_id
has_many :reviews, through: :bookings
belongs_to :role
end
# app/models/role.rb
class Role < ApplicationRecord
has_many :users
end
# app/models/service.rb
class Service < ApplicationRecord
belongs_to :supplier, class_name: 'User'
has_many :bookings
has_many :reviews, through: :bookings
end
# app/models/booking.rb
class Booking < ApplicationRecord
belongs_to :customer, class_name: 'User'
belongs_to :service
has_one :review
end
# app/models/review.rb
class Review < ApplicationRecord
belongs_to :booking
has_one :customer, through: :booking
has_one :service, through: :booking
end
This setup will provide the necessary models and associations for your application. Users can be suppliers or customers, services are provided by suppliers, customers can make bookings for services, and reviews can be written by customers after a booking.