Skip to main content
Ask A Question
Notifications
You’re not receiving notifications from this thread.
Subscribe

How do I structure a Bookings table for two models?

Databases • Asked by Taylor Cooney

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.


Login or Create An Account to join the conversation.

Subscribe to the newsletter

Join 31,152+ developers who get early access to new screencasts, articles, guides, updates, and more.

    By clicking this button, you agree to the GoRails Terms of Service and Privacy Policy.

    More of a social being? We're also on Twitter and YouTube.