All threads / How do I structure a Bookings table for two models?

Ask A Question

Notifications

You’re not receiving notifications from this thread.

How do I structure a Bookings table for two models?

Taylor Cooney asked in Databases

I've primarly built out support to book a flight, and now I'm looking to offer the ability to book a hotel as well. I'm looking for some insight on the best way to model this:

Currently there is a Reservations table that has a flight_id and user_id. Does it make sense to create an entirely new table for Hotel reservations, or modify the exisiting Reservations table to support polymorphic assocaitons? Instead of flight_id, it would have a reservable_type and reservable_id. Off the top of my mind, ActiveRecord will be unable to build any join from a polymorphic assocation without additional information.

Join the discussion

Want to stay up-to-date with Ruby on Rails?

Join 35,095+ developers who get early access to new tutorials, screencasts, articles, and more.

    We care about the protection of your data. Read our Privacy Policy.

    logo Created with Sketch.

    Ruby on Rails tutorials, guides, and screencasts for web developers learning Ruby, Rails, Javascript, Turbolinks, Stimulus.js, Vue.js, and more. Icons by Icons8

    © 2020 GoRails, LLC. All rights reserved.