Share My Bike, a Rails project

class Bicycle < ApplicationRecord
belongs_to :owner, class_name: "User"
has_many :trips
has_many :renters, class_name: "User", through: :trips
class Trip < ApplicationRecord
belongs_to :bicycle
belongs_to :renter, class_name: "User"
class User < ApplicationRecord
has_many :bicycles, foreign_key: :owner_id
has_many :trips, through: :bicycles
has_many :reservations, foreign_key: :renter_id, class_name: "Trip"

It’s all over the place, I am not managing to do anything, what do I do? Do I use Single Table Inheritance or Polymorphic Associations? Which resources do I nest? How do I create trips?



Get the Medium app

A button that says 'Download on the App Store', and if clicked it will lead you to the iOS App store
A button that says 'Get it on, Google Play', and if clicked it will lead you to the Google Play store