#Building a reservation system

21 messages · Page 1 of 1 (latest)

azure slate
#

When you say, Previous Reservation, I assume you mean time based?

barren scarab
#

yes, how should that constraint be enforced since it should not be done in the models?

azure slate
#

By going with an FK for previous reservation you're creating a chain of reservations. I'm not sure that's the ideal model design...

#

Looking at this I'd take a step back and think about requirements and what happens in the real-world...

Assuming that a customer can have many reservations with a hotel, then perhaps the relationship might make sense as:

  • The org has many properties.
  • The customer can rent any number of properties.
  • I assume that a customer can only rent one property at a time.
  • You want to track all rentals over time by a customer.

Does that sound correct?

barren scarab
#

There should only be those 2 models

azure slate
#

This, dear community member, is a useful mindset to take into development. It really helps to write out what you're trying to accomplish, to analyze the processes/procedures before designing the data model schema.

From the above, you can then dive into how to think about the model. You might want to consider the following tables

  • each Property
  • can have many Reservations
  • each property can be reserved by 1 Customer/Renter at a time...
barren scarab
#

I will give you that it sounds more logical but I saw this online and the solution should work only with those 2 models.

#

It does not have to be through a FK it can be set in the view

azure slate
#

Not all tutorials are equal. Might I suggest a video tutorial by Corey Schafer on YouTube. It will get you learning the concepts in a much more sensible way. The danger with following this tutorial is that it causes more confusion than is necessary. It's a very bad choice of tutorial topic.

barren scarab
#

Thanks for the recommendation, I'll take a look. Do you also think a good workaround for using only 2 models would be to use html tables ?

azure slate
barren scarab
#

I would say the solution works if the data is displayed as in the tables on the picture. Perhaps the necessary data can be extracted from the 2 models and manipulated to be shown on the html tables like in the picture

azure slate
#

I'd rename the field previous_reservation to reservation and move it over to the Rentals table. Then, I'd focus on a list view for rentals showing the list of reservations by querying for all reservations with a reservation FK matching the Rental.

#

The idea behind that is that a Rental (one) can have (many) Reservations ...thus one to many. Does that make sense?

barren scarab
#

I will try it

azure slate
barren scarab
#

thanks!

#

and how would you do the "previous reservation is a reservation that is before the current one"?

#

As a constraint in the FK of reservation in the rental?